Class: BeyondApi::Products

Inherits:
Base
  • Object
show all
Includes:
ProductAttachments, ProductAvailability, ProductCrossSells, ProductCustomAttributes, ProductImages, ProductSearches, ProductVariationProperties, ProductVideos, Utils
Defined in:
lib/beyond_api/resources/products.rb

Instance Attribute Summary

Attributes inherited from Base

#session

Instance Method Summary collapse

Methods included from Utils

#file_content_type, #handle_all_request, #handle_error, #handle_response, #sanitize_key, #sanitize_response, #to_object_struct

Methods included from ProductVideos

#add_video, #delete_video, #update_video, #video, #videos

Methods included from ProductVariationProperties

#update_variation_properties, #variation_properties

Methods included from ProductSearches

#search, #search_by_sku, #search_tags_starting_by

Methods included from ProductImages

#add_image, #delete_image, #image, #images, #set_image_as_default, #sort_images, #upload_image, #upload_multiple_images

Methods included from ProductCustomAttributes

#create_custom_attribute, #custom_attribute, #custom_attributes, #delete_custom_attribute, #update_custom_attribute

Methods included from ProductCrossSells

#create_cross_sell, #cross_sell, #cross_sells, #delete_cross_sell, #update_cross_sell

Methods included from ProductAvailability

#adjust_stock_level, #availability, #disable_purchasability, #disable_stock_management, #enable_purchasability, #enable_stock_management, #update_reserve_stock

Methods included from ProductAttachments

#add_attachment, #attachment, #attachments, #delete_attachment

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from BeyondApi::Base

Instance Method Details

#all(params = {}) ⇒ OpenStruct

A GET request will list all of the products in a paged manner. The returned data is an excerpt projection, which includes a small subset of product properties.

$ curl 'https://api-shop.beyondshop.cloud/api/products' -i -X GET \
    -H 'Content-Type: application/hal+json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@products = session.products.all(size: 100, page: 0)

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :paginated (Boolean)
  • :size (Integer)

    the page size

  • :page (Integer)

    the page number

Returns:

  • (OpenStruct)

Scopes:

  • prod:r



45
46
47
48
49
# File 'lib/beyond_api/resources/products.rb', line 45

def all(params = {})
  path = "/products"

  handle_all_request(path, :products, params)
end

#assign_variation_attribute_as_differentiator(product_id, variation_attribute_id) ⇒ true

A POST request is used to assign a variation attribute as the variation images differentiator for a variation product.

Examples:

session.products.assign_variation_images_differentiator("f205294b-17dc-4f75-8b5e-5df72abb96df", "491fedf4-37a9-4bcf-98b8-cff2f82879b7")

Parameters:

  • product_id (String)

    the product UUID

  • variation_attribute_id (String)

    the variation attribute UUID

Returns:

  • (true)

Scopes:



289
290
291
292
293
294
295
296
# File 'lib/beyond_api/resources/products.rb', line 289

def assign_variation_attribute_as_differentiator(product_id, variation_attribute_id)
  path = "/products/#{product_id}/variation-attributes/#{variation_attribute_id}/make-differentiator"

  response, status = BeyondApi::Request.post(@session,
                                             path)

  handle_response(response, status, respond_with_true: true)
end

#create(body) ⇒ OpenStruct Also known as: create_variation

A POST request is used to create a product.

$ curl 'https://api-shop.beyondshop.cloud/api/products' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
  "sku" : "123456789-001",
  "name" : "Rioja Castillo de Puerto (2013)",
  "description" : "Spain\nRioja Tempranillo",
  "manufacturer" : "Grape Vineyard",
  "essentialFeatures" : "Dry. 12% alcohol. Best vine variety.",
  "tags" : [ "Bestseller", "Red Wine", "Sale" ],
  "productIdentifiers" : [ {
    "type" : "EAN",
    "value" : "9780134308135"
  } ],
  "salesPrice" : {
    "taxModel" : "NET",
    "amount" : 8.7,
    "currency" : "EUR"
  },
  "listPrice" : {
    "taxModel" : "NET",
    "amount" : 10.95,
    "currency" : "EUR"
  },
  "manufacturerPrice" : {
    "taxModel" : "NET",
    "amount" : 99.95,
    "currency" : "EUR"
  },
  "visible" : true,
  "taxClass" : "REGULAR",
  "shippingWeight" : 100,
  "maxOrderQuantity" : 6,
  "shippingDimension" : {
    "length" : 1500,
    "width" : 1000,
    "height" : 2000
  },
  "refPrice" : {
    "refQuantity" : 1,
    "unit" : "LITER",
    "quantity" : 0.75,
    "price" : {
      "taxModel" : "NET",
      "amount" : 11.6,
      "currency" : "EUR"
    }
  },
  "shippingPeriod" : {
    "min" : 2,
    "max" : 4,
    "displayUnit" : "WEEKS"
  }
}'

Examples:

body = {
 "sku": "123456789-001",
 "name": "Rioja Castillo de Puerto (2013)",
 "description": "Spain\nRioja Tempranillo",
 "manufacturer": "Grape Vineyard",
 "essentialFeatures": "Dry. 12% alcohol. Best vine variety.",
 "tags": ["Bestseller", "Red Wine", "Sale"],
 "productIdentifiers": [{
   "type": "EAN",
   "value": "9780134308135"
 }],
 "salesPrice": {
   "taxModel": "NET",
   "amount": 8.7,
   "currency": "EUR"
 },
 "listPrice": {
   "taxModel": "NET",
   "amount": 10.95,
   "currency": "EUR"
 },
 "manufacturerPrice": {
   "taxModel": "NET",
   "amount": 99.95,
   "currency": "EUR"
 },
 "visible": true,
 "taxClass": "REGULAR",
 "shippingWeight": 100,
 "maxOrderQuantity": 6,
 "shippingDimension": {
   "length": 1500,
   "width": 1000,
   "height": 2000
 },
 "refPrice": {
   "refQuantity": 1,
   "unit": "LITER",
   "quantity": 0.75,
   "price": {
     "taxModel": "NET",
     "amount": 11.6,
     "currency": "EUR"
   }
 },
 "shippingPeriod": {
   "min": 2,
   "max": 4,
   "displayUnit": "WEEKS"
 }
}

@product = session.products.create(body)

Parameters:

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • prod:c



170
171
172
173
174
175
176
177
178
# File 'lib/beyond_api/resources/products.rb', line 170

def create(body)
  path = "/products"

  response, status = BeyondApi::Request.post(@session,
                                             path,
                                             body)

  handle_response(response, status)
end

#delete(product_id) ⇒ Object

A DELETE request is used to delete a product or variation product. When a variation product is deleted, all its variations are deleted as well.

$ curl 'https://api-shop.beyondshop.cloud/api/products/c06c61af-f99a-4698-90fa-8c3199ca732f' -i -X DELETE \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

session.products.delete("c06c61af-f99a-4698-90fa-8c3199ca732f")

Parameters:

  • product_id (String)

    the product UUID

Returns:

  • true

Scopes:

  • prod:d



196
197
198
199
200
201
202
203
# File 'lib/beyond_api/resources/products.rb', line 196

def delete(product_id)
  path = "/products/#{product_id}"

  response, status = BeyondApi::Request.delete(@session,
                                               path)

  handle_response(response, status, respond_with_true: true)
end

#find(product_id) ⇒ OpenStruct Also known as: find_variation

A GET request is used to retrieve the details of a product.

$ curl 'https://api-shop.beyondshop.cloud/api/products/75ebcb57-aefb-4963-8225-060c528e070d' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@product = session.products.find("75ebcb57-aefb-4963-8225-060c528e070d")

Parameters:

  • product_id (String)

    the product UUID

Returns:

  • (OpenStruct)

Scopes:

  • prod:r



222
223
224
225
226
227
228
229
# File 'lib/beyond_api/resources/products.rb', line 222

def find(product_id)
  path = "/products/#{product_id}"

  response, status = BeyondApi::Request.get(@session,
                                            path)

  handle_response(response, status)
end

#update(product_id, body) ⇒ OpenStruct Also known as: update_variation

A PATCH request is used to update a product partially with json content type.

Examples:

body = {
  "name": "patched name",
  "description": "patched description. <p><br></p><blockquote> <ol><li><strong>\n<h1></h1><h6></h6><em><a href=\"http://example.com\" target=\"_blank\"><u>this is my test html</u></a>\n</em></strong> </li></ol> </blockquote>",
  "productIdentifiers": null,
  "manufacturer": "patched manufacturer"
}
@product = session.products.update("b69e3f47-03b8-40d2-843c-ae89a3d9bcdd", body)

Parameters:

  • product_id (String)

    the product UUID

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • prod:u

    $ curl ‘api-shop.beyondshop.cloud/api/products/b69e3f47-03b8-40d2-843c-ae89a3d9bcdd’ -i -X PATCH \

    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
    "name" : "patched name",
    "description" : "patched description. <p><br></p><blockquote> <ol><li><strong>\n<h1></h1><h6></h6><em><a href=\"http://example.com\" target=\"_blank\"><u>this is my test html</u></a>\n</em></strong> </li></ol> </blockquote>",
    "productIdentifiers" : null,
    "manufacturer" : "patched manufacturer"
    

    }‘



261
262
263
264
265
266
267
268
269
# File 'lib/beyond_api/resources/products.rb', line 261

def update(product_id, body)
  path = "/products/#{product_id}"

  response, status = BeyondApi::Request.patch(@session,
                                              path,
                                              body)

  handle_response(response, status)
end