Module: BeyondApi::ProductCustomAttributes

Included in:
Products
Defined in:
lib/beyond_api/resources/products/custom_attributes.rb

Instance Method Summary collapse

Instance Method Details

#create_custom_attribute(product_id, body) ⇒ OpenStruct

A POST request is used to create a product attribute, which defines the value of a certain product attribute definition for a specific product.

$ curl 'https://api-shop.beyondshop.cloud/api/products/0c0e1699-d2a4-44d0-bed9-64b2fa1a7713/attributes' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
    "key" : "colour",
    "value" : "Yellow"
}'

Examples:

body = {
  "key" => "colour",
  "value" => "Yellow"
}

@custom_attribute = session.products.create_custom_attribute("0c0e1699-d2a4-44d0-bed9-64b2fa1a7713", body)

Parameters:

  • product_id (String)

    the product UUID

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • prat:c



33
34
35
36
37
# File 'lib/beyond_api/resources/products/custom_attributes.rb', line 33

def create_custom_attribute(product_id, body)
  response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/attributes", body)

  handle_response(response, status)
end

#custom_attribute(product_id, attribute_name) ⇒ OpenStruct

A GET request is used to retrieve detailed information about a specific product attribute.

$ curl 'https://api-shop.beyondshop.cloud/api/products/d389347c-568e-4785-8216-91e4f8850c66/attributes/key' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <Access token>'

Examples:


@custom_attribute = session.products.custom_attribute("d389347c-568e-4785-8216-91e4f8850c66", "key")

Parameters:

  • product_id (String)

    the product UUID

  • attribute_name (String)

    the key of custom attribute

Returns:

  • (OpenStruct)

Scopes:

  • prat:r



57
58
59
60
61
# File 'lib/beyond_api/resources/products/custom_attributes.rb', line 57

def custom_attribute(product_id, attribute_name)
  response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/attributes/#{attribute_name}")

  handle_response(response, status)
end

#custom_attributes(product_id) ⇒ OpenStruct

A GET request is used to retrieve all product attributes for a product.

$ curl 'https://api-shop.beyondshop.cloud/api/products/57f0ef04-9dac-462f-9dd4-606f7551cc7b/attributes' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <Access token>'

Examples:


@custom_attributes = session.products.custom_attributes("57f0ef04-9dac-462f-9dd4-606f7551cc7b")

Parameters:

  • product_id (String)

    the product UUID

Returns:

  • (OpenStruct)

Scopes:

  • prat:r



80
81
82
83
84
# File 'lib/beyond_api/resources/products/custom_attributes.rb', line 80

def custom_attributes(product_id)
  response, status = BeyondApi::Request.get(@session, "/products/#{product_id}/attributes")

  handle_response(response, status)
end

#delete_custom_attribute(product_id, attribute_name) ⇒ OpenStruct

A DELETE request is used to delete a product attribute.

$ curl 'https://api-shop.beyondshop.cloud/api/products/fec3b6f3-83d0-467a-abc5-d51019e57b51/attributes/farbe' -i -X DELETE \
    -H 'Authorization: Bearer <Access token>'

Examples:


session.products.delete_custom_attribute("fec3b6f3-83d0-467a-abc5-d51019e57b51", "farbe")

Parameters:

  • product_id (String)

    the product UUID

  • attribute_name (String)

    the key of custom attribute

Returns:

  • (OpenStruct)

Scopes:

  • prat:d



103
104
105
106
107
# File 'lib/beyond_api/resources/products/custom_attributes.rb', line 103

def delete_custom_attribute(product_id, attribute_name)
  response, status = BeyondApi::Request.delete(@session, "/products/#{product_id}/attributes/#{attribute_name}")

  handle_response(response, status, respond_with_true: true)
end

#update_custom_attribute(product_id, attribute_name, body) ⇒ OpenStruct

A PUT request is used to update the value of a product attribute. If the specified product attribute doesn’t exist, it will be created with the response as described in Create product attribute.

$ curl 'https://api-shop.beyondshop.cloud/api/products/82ed44e9-664d-47c0-8b07-09adecfdbf20/attributes/key' -i -X PUT \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
  "value" : "green"
}'

Examples:

body = {
  "value" : "green"
 }

@custom_attribute = session.products.update_custom_attribute("82ed44e9-664d-47c0-8b07-09adecfdbf20", "key", body)

Parameters:

  • product_id (String)

    the product UUID

  • attribute_name (String)

    the key of custom attribute

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • prat:u



134
135
136
137
138
# File 'lib/beyond_api/resources/products/custom_attributes.rb', line 134

def update_custom_attribute(product_id, attribute_name, body)
  response, status = BeyondApi::Request.put(@session, "/products/#{product_id}/attributes/#{attribute_name}", body)

  handle_response(response, status)
end