Shopify functions

Use Shopify functions to interact with your Shopify products and shopping carts within your chatbot.

These functions wrap common uses of the Shopify API to make it easier to use in your scripts. Refer to the Shopify API documentation for examples of responses and data structures.

To use the Shopify functions in a chatbot script:

  1. Make sure you've created a Shopify integration for your chatbot.
  2. Load the Shopify functions into the script.

     const shopify = bot.extensions.require("shopify") 

All Shopify functions are asynchronous. Make sure you await the result in your scripts.

Pagination

All Shopify functions that return arrays of objects that can be paginated use the Relay format for pagination. For more information on using Relay, see the Relay documentation.

You can pass parameters for pagination using the optional relayOptions parameter.

Property Type Required Description
pageSize int Yes Number of items to fetch in the page.
after string Yes ID of the item that immediately precedes this page of items.

Product functions

shopify.​store.​getProducts​(params, relayOptions)

Get a paginated list of products that match the provided query. See the Shopify API search syntax documentation for more information on formatting queries.

The params parameter should have the following properties:

Property Type Required Description
query string Yes Query to pass to Shopify to retrieve products.

 

shopify.​store.​getProduct​(params, relayOptions)

Get information about a single product, including a paginated list of product variants.

See the Shopify API documentation for example responses.

The params parameter should have the following properties:

Property Type Required Description
productId string Yes Unique ID of the product to retrieve.

 

shopify.​store.​getProductVariantByOptions​(params, relayOptions)

Get a paginated list of all variants of a single product that match the specified option values.

The params parameter should have the following properties:

Property Type Required Description
productId string Yes Unique ID of the product to retrieve.
selectedOptions array<string> Yes

The variant options to filter to.

Only the options you specify are applied as a filter. Any option you don't specify is ignored.

For example, a product has a "colour" option and a "size" option. Specifying a colour option of "red" returns all sizes of the product that are red.

 

shopify.​store.​getCollection​(params, relayOptions)

Get  a paginated list of products from the specified collection.

Property Type Required Description
collectionId string Yes Unique identifier of the Shopify collection.

 

User cart functions

shopify.​user.​getCartId()

Get the internal cart ID associated with the current chatbot user to use with custom queries.

Your chatbot automatically associates the chatbot user with their Shopify cart; this function is only needed for custom queries and advanced use cases. 

shopify.​user.​getCart​(relayOptions)

Get the JSON of the user's shopping cart. Includes a paginated list of the cart line items (product variants and quantities) that are currently in the user's shopping cart.

See the Shopify API reference for example responses.

shopify.​user.​addToCart​(params)

Add a product variant and quantity to the user's shopping cart. Once added, the product variant and quantity are contained in the shopping cart object in a unique cart line item. Returns a JSON object of the cart line item.

See the Shopify API reference for example responses, and for more information on different situations, such as if you add an item that already exists in the cart.

Property Type Required Description
merchandiseId string Yes ID of the variant of the product to add to the shopping card.
quantity number Yes Number of units of this variant to add.

 

shopify.​user.​removeCartLine​(params)

Delete the specified cart line item (a product variant and quantity) from the user's shopping cart. Returns the JSON of the updated shopping cart.

Property Type Required Description
cartLineId string Yes The unique identifier of the cart line to delete.

 

shopify.​user.​updateCartLine​(params)

Update the specified cart line item (a product variant and quantity) in the user's shopping cart with a new product variant and/or new quantity. Returns the JSON of the updated shopping cart.

See the Shopify API reference for example responses.

Property Type Required Description
cartLineId string Yes The unique identifier of the cart line to update.
merchandiseId string Yes ID of the variant of the product to set at this cart line.
quantity number Yes Number of units of this variant to set at this cart line.
Was this article helpful?
0 out of 0 found this helpful