Module: BeyondApi::ProductSearches

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

Instance Method Summary collapse

Instance Method Details

#search(body) ⇒ OpenStruct

A POST request is used to search for products by a search term. Optionally, you can also filter the search results.

$ curl 'https://api-shop.beyondshop.cloud/api/products/search' -i -X POST \
    -H 'Content-Type: application/hal+json;charset=UTF-8' \
    -H 'Accept: application/hal+json' \
      -H 'Authorization: Bearer <Access token>'
      -d '{
    "search" : {
      "term" : "Tony Highfinger, Poloshirt, Men",
      "category" : "NAME"
    },
    "filters" : [ {
      "key" : "status",
      "values" : [ "PUBLISHED" ]
    } ],
    "paging" : {
      "page" : 0,
      "pageSize" : 20,
      "sort" : {
        "property" : "name",
        "direction" : "ASC"
      }
    }
}'

Examples:

body = {
  search: {
    term: "Tony Highfinger, Poloshirt, Men",
    category: "NAME"
  },
  filters: [ {
    key: "status",
    values: [ "PUBLISHED" ]
  } ],
  paging: {
    page: 0,
    page_size: 20,
    sort: {
      property: "name",
      direction: "ASC"
    }
  }
}
@products = session.product.search(body)

Parameters:

  • body (String)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • prod:r



60
61
62
63
64
65
66
# File 'lib/beyond_api/resources/products/searches.rb', line 60

def search(body)
  response, status = BeyondApi::Request.post(@session,
                                             "/products/search",
                                             body)

  handle_response(response, status)
end

#search_by_sku(sku) ⇒ OpenStruct

A GET request is used to search for a product by SKU.

$ curl 'https://api-shop.beyondshop.cloud/api/products/search/find-by-sku?sku=vino020' -i -X GET \
    -H 'Authorization: Bearer <Access token>'

Examples:

@product = session.product.search_by_sku("vino020")

Parameters:

  • sku (String)

    the product sku to search

Returns:

  • (OpenStruct)

Scopes:

  • prod:r



83
84
85
86
87
# File 'lib/beyond_api/resources/products/searches.rb', line 83

def search_by_sku(sku)
  response, status = BeyondApi::Request.get(@session, "/products/search/find-by-sku", sku: sku)

  handle_response(response, status)
end

#search_tags_starting_by(starts_with, params = {}) ⇒ OpenStruct

A GET request is used to search used tags by a starting string. All strings are sorted by usage, starting with the biggest.

$ curl 'https://api-shop.beyondshop.cloud/api/products/search/tags?startsWith=aw' -i -X GET \
    -H 'Authorization: Bearer <Access token>'

Examples:

@tags = session.product.search_tags_starting_by("aw")

Parameters:

  • starts_with (String)

    the tag start to search

  • param (Hash)

    a customizable set of options

Returns:

  • (OpenStruct)

Scopes:

  • prod:r



106
107
108
109
110
111
# File 'lib/beyond_api/resources/products/searches.rb', line 106

def search_tags_starting_by(starts_with, params = {})
  response, status = BeyondApi::Request.get(@session, "/products/search/tags",
                                            params.merge(starts_with: starts_with))

  handle_response(response, status)
end