Sync product data from an external source
Use the productSet
mutation to sync the desired state of a product with data from an external source in a single operation
This mutation is suited for apps and use cases where the state of the product model is managed outside of Shopify, for example with an Enterprise Resource Planning (ERP) system or Worksheet, and you want to update Shopify's product model to reflect your external state.
The mutation is available in both asynchronous and synchronous modes. The default is asynchronous. The productSet
mutation has an input limit of 2K variants when run asynchronously and only 100 variants when run synchronously.
This guide provides examples of how to create and update products asynchronously and synchronously, with data from an external source.
Create a product with variants and options asynchronously
Anchor link to section titled "Create a product with variants and options asynchronously"The following productSet
mutation initiates an asynchronous operation to create a product with an option named Color
. The option has three possible values: Red
, Green
, and Blue
. The mutation also sets up product variants, each associated with one of the color options.
The response to the mutation indicates that the operation has been successfully initiated with the status CREATED
.
Variant GID | Option name | Option value name |
---|---|---|
gid://shopify/ProductVariant/1 |
Color |
Red |
gid://shopify/ProductVariant/2 |
Color |
Green |
gid://shopify/ProductVariant/3 |
Color |
Blue |
Check the status of the operation
Anchor link to section titled "Check the status of the operation"Use the productOperation
query to check the status of the operation, using the ID that was returned when the product was created.
The query response indicates that the operation is COMPLETE
and provides the details of the created product.
Update the product data asynchronously
Anchor link to section titled "Update the product data asynchronously"The following productSet
mutation initiates an asynchronous operation to update an existing product's Color
option. The original color values of Red
, Green
, and Blue
are replaced with new values of Maroon
, Forest Green
, and Deep Sea Blue
. The mutation also updates the product variants from the old color values to the new ones. Each variant retains its original GID.
Variant GID | Option name | Option value name |
---|---|---|
gid://shopify/ProductVariant/1 |
Color |
Deep Sea Blue |
gid://shopify/ProductVariant/2 |
Color |
Forest Green |
gid://shopify/ProductVariant/3 |
Color |
Maroon |
The response to the mutation indicates that the operation has been successfully initiated with the status CREATED
.
Query the updated product asynchronously
Anchor link to section titled "Query the updated product asynchronously"After the product has been updated asynchronously, use the productOperation
query to retrieve the updated product data. This query uses the ProductSetOperation
object to check the status of the operation and to retrieve the details of the updated product and its variants.
The response to this query indicates that the operation is COMPLETE
, and indicates that the product's title has been updated, and the color options have been updated to Deep Sea Blue
, Forest Green
, and Maroon
.
Create a product with variants and options synchronously
Anchor link to section titled "Create a product with variants and options synchronously"The following productSet
mutation creates a product with an option named Color
. The option has three possible values, Red
, Green
, and Blue
. The mutation creates product variants where each is associated with one of the color options. Each variant is identified by a globally-unique ID.
The mutation runs synchronously because the synchronous
field is set.
Variant GID | Option name | Option value name |
---|---|---|
gid://shopify/ProductVariant/1 |
Color |
Red |
gid://shopify/ProductVariant/2 |
Color |
Green |
gid://shopify/ProductVariant/3 |
Color |
Blue |
Update the product data synchronously
Anchor link to section titled "Update the product data synchronously"The following productSet
mutation updates the existing product's Color
option. The original color values Red
, Green
, and Blue
are replaced with new values of Maroon
, Forest Green
, and Deep Sea Blue
. The mutation also updates the product variants from the old color values to the new ones. Each variant retains its original GID.
The mutation runs synchronously because the synchronous
field is set.
Variant GID | Option name | Option value name |
---|---|---|
gid://shopify/ProductVariant/1 |
Color |
Deep Sea Blue |
gid://shopify/ProductVariant/2 |
Color |
Forest Green |
gid://shopify/ProductVariant/3 |
Color |
Maroon |