Class: CollectionResource

CollectionResource()

The JS Buy SDK collection resource

Constructor

new CollectionResource()

Source:

Methods

fetch(id) → {Promise|GraphModel}

Fetches a single collection by ID on the shop, not including products. To fetch the collection with products use fetchWithProducts.

Parameters:
Name Type Description
id String

The id of the collection to fetch.

Source:
Returns:

A promise resolving with a GraphModel of the collection.

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

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

Fetches all collections on the shop, not including products. To fetch collections with products use fetchAllsWithProducts.

Source:
Returns:

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

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

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

Fetches all collections on the shop, including products.

Source:
Returns:

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

Type
Promise | Array.<GraphModel>
Example
client.collection.fetchAllWithProducts().then((collections) => {
  // Do something with the collections
});

fetchByHandle(handle) → {Promise|GraphModel}

Fetches a collection by handle on the shop.

Parameters:
Name Type Description
handle String

The handle of the collection to fetch.

Source:
Returns:

A promise resolving with a GraphModel of the collection.

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

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

Fetches all collections 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 Collection 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 collections.

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

fetchWithProducts(id) → {Promise|GraphModel}

Fetches a single collection by ID on the shop, including products.

Parameters:
Name Type Description
id String

The id of the collection to fetch.

Source:
Returns:

A promise resolving with a GraphModel of the collection.

Type
Promise | GraphModel
Example
client.collection.fetchWithProducts('Xk9lM2JkNzFmNzIQ4NTIY4ZDFiZTUyZTUwNTE2MDNhZjg==').then((collection) => {
  // Do something with the collection
});