The JS Buy SDK is deprecated as of January, 2025. For more information, please see the README.

Class: ProductResource

ProductResource()

The JS Buy SDK product resource

Constructor

new ProductResource()

Source:

Methods

fetch(id) → {Promise|GraphModel}

Fetches a single product by ID on the shop.

Parameters:
Name Type Description
id String

The id of the product to fetch.

Source:
Returns:

A promise resolving with a GraphModel of the product.

Type
Promise | GraphModel
Example
client.product.fetch('Xk9lM2JkNzFmNzIQ4NTIY4ZDFi9DaGVja291dC9lM2JkN==').then((product) => {
  // Do something with the product
});

fetchAll(pageSizeopt) → {Promise|Array.<GraphModel>}

Fetches all products on the shop.

Parameters:
Name Type Attributes Description
pageSize Int <optional>

The number of products to fetch per page

Source:
Returns:

A promise resolving with an array of GraphModels of the products.

Type
Promise | Array.<GraphModel>
Example
client.product.fetchAll().then((products) => {
  // Do something with the products
});

fetchByHandle(handle) → {Promise|GraphModel}

Fetches a single product by handle on the shop.

Parameters:
Name Type Description
handle String

The handle of the product to fetch.

Source:
Returns:

A promise resolving with a GraphModel of the product.

Type
Promise | GraphModel
Example
client.product.fetchByHandle('my-product').then((product) => {
  // Do something with the product
});

fetchMultiple(ids) → {Promise|Array.<GraphModel>}

Fetches multiple products by ID on the shop.

Parameters:
Name Type Description
ids Array.<String>

The ids of the products to fetch

Source:
Returns:

A promise resolving with a GraphModel of the product.

Type
Promise | Array.<GraphModel>
Example
const ids = ['Xk9lM2JkNzFmNzIQ4NTIY4ZDFi9DaGVja291dC9lM2JkN==', 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ='];
client.product.fetchMultiple(ids).then((products) => {
  // Do something with the products
});

fetchQuery(argsopt) → {Promise|Array.<GraphModel>}

Fetches all products on the shop that match the query.

Parameters:
Name Type Attributes Description
args Object <optional>

An object specifying the query data containing zero or more of:

Properties
Name Type Attributes Default Description
first Int <optional>
20

The relay first param. This specifies page size.

sortKey String <optional>
ID

The key to sort results by. Available values are documented as Product Sort Keys.

query String <optional>

A query string. See full documentation here

reverse Boolean <optional>

Whether or not to reverse the sort order of the results

Source:
Returns:

A promise resolving with an array of GraphModels of the products.

Type
Promise | Array.<GraphModel>
Example
client.product.fetchQuery({first: 20, sortKey: 'CREATED_AT', reverse: true}).then((products) => {
  // Do something with the first 10 products sorted by title in ascending order
});

fetchRecommendations(productId) → {Promise|Array.<GraphModel>}

Find recommended products related to a given productId. To learn more about how recommendations are generated, see https://shopify.dev/themes/product-merchandising/recommendations.

Parameters:
Name Type Description
productId String

The id of the product to fetch.

Source:
Returns:

A promise resolving with an array of GraphModels of the products.

Type
Promise | Array.<GraphModel>
Example
const productId 'Xk9lM2JkNzFmNzIQ4NTIY4ZDFi9DaGVja291dC9lM2JkN==';
client.product.fetchProductRecommendations(productId).then((products) => {
  // Do something with the products
});