productSet
Requires access scope. Also: The user must have a permission to create products.
Creates or updates a product in a single request.
Use this mutation when syncing information from an external data source into Shopify.
When using this mutation to update a product, specify that product's id
in the input.
Any list field (e.g. collections, metafields, variants) will be updated so that all included entries are either created or updated, and all existing entries not included will be deleted.
All other fields will be updated to the value passed. Omitted fields will not be updated.
When run in synchronous mode, you will get the product back in the response.
For versions 2024-04
and earlier, the synchronous mode has an input limit of 100 variants.
This limit has been removed for versions 2024-07
and later.
In asynchronous mode, you will instead get a
ProductSetOperation
object back. You can then use the
productOperation query to
retrieve the updated product data. This query uses the object to
check the status of the operation and to retrieve the details of the updated product and its variants.
If you need to update a subset of variants, use one of the bulk variant mutations:
If you need to update options, use one of the product option mutations:
See our guide to sync product data from an external source for more.
Arguments
- Anchor to inputinput•Product
Set requiredInput! The properties of the newly created or updated product.
- Anchor to synchronoussynchronous•BooleanDefault:true
Whether the mutation should be run synchronously or asynchronously.
If
true
, the mutation will return the updatedproduct
.If
false
, the mutation will return a.
Defaults to
true
.Setting
synchronous: false
may be desirable depending on the input complexity/size, and should be used if you are experiencing timeouts.Note: When run in the context of a bulk operation, the mutation will always run synchronously and this argument will be ignored.
Anchor to ProductSetPayload returnsProductSetPayload returns
- Anchor to productproduct•
The product object.
- Anchor to productSetOperationproduct•
Set Operation The product set operation, returned when run in asynchronous mode.
- Anchor to userErrorsuser•
Errors [ProductSet non-nullUser Error!]! The list of errors that occurred from executing the mutation.
- Asynchronously create a product with two variants
- Create a product with customized inventory quantities
- Create a product with files
- Create a product with two options and four variants
- Remove custom options and variants from a product
- Update product variant pricing referencing options and variants by Ids
- Update product variant pricing referencing options and variants by Ids
- productSet reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation createProductAsynchronous($productSet: ProductSetInput!, $synchronous: Boolean!) {6 productSet(synchronous: $synchronous, input: $productSet) {7 product {8 id9 }10 productSetOperation {11 id12 status13 userErrors {14 code15 field16 message17 }18 }19 userErrors {20 code21 field22 message23 }24 }25 }`,26 {27 variables: {28 "synchronous": false,29 "productSet": {30 "title": "Winter hat",31 "productOptions": [32 {33 "name": "Color",34 "position": 1,35 "values": [36 {37 "name": "Grey"38 },39 {40 "name": "Black"41 }42 ]43 }44 ],45 "variants": [46 {47 "optionValues": [48 {49 "optionName": "Color",50 "name": "Grey"51 }52 ],53 "price": 79.9954 },55 {56 "optionValues": [57 {58 "optionName": "Color",59 "name": "Black"60 }61 ],62 "price": 69.9963 }64 ]65 }66 },67 },68);6970const data = await response.json();71
mutation createProductAsynchronous($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
}
productSetOperation {
id
status
userErrors {
code
field
message
}
}
userErrors {
code
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation createProductAsynchronous($productSet: ProductSetInput!, $synchronous: Boolean!) { productSet(synchronous: $synchronous, input: $productSet) { product { id } productSetOperation { id status userErrors { code field message } } userErrors { code field message } } }",
"variables": {
"synchronous": false,
"productSet": {
"title": "Winter hat",
"productOptions": [
{
"name": "Color",
"position": 1,
"values": [
{
"name": "Grey"
},
{
"name": "Black"
}
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Color",
"name": "Grey"
}
],
"price": 79.99
},
{
"optionValues": [
{
"optionName": "Color",
"name": "Black"
}
],
"price": 69.99
}
]
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createProductAsynchronous($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
}
productSetOperation {
id
status
userErrors {
code
field
message
}
}
userErrors {
code
field
message
}
}
}`,
{
variables: {
"synchronous": false,
"productSet": {
"title": "Winter hat",
"productOptions": [
{
"name": "Color",
"position": 1,
"values": [
{
"name": "Grey"
},
{
"name": "Black"
}
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Color",
"name": "Grey"
}
],
"price": 79.99
},
{
"optionValues": [
{
"optionName": "Color",
"name": "Black"
}
],
"price": 69.99
}
]
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation createProductAsynchronous($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
}
productSetOperation {
id
status
userErrors {
code
field
message
}
}
userErrors {
code
field
message
}
}
}`,
"variables": {
"synchronous": false,
"productSet": {
"title": "Winter hat",
"productOptions": [
{
"name": "Color",
"position": 1,
"values": [
{
"name": "Grey"
},
{
"name": "Black"
}
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Color",
"name": "Grey"
}
],
"price": 79.99
},
{
"optionValues": [
{
"optionName": "Color",
"name": "Black"
}
],
"price": 69.99
}
]
}
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation createProductAsynchronous($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
}
productSetOperation {
id
status
userErrors {
code
field
message
}
}
userErrors {
code
field
message
}
}
}
QUERY
variables = {
"synchronous": false,
"productSet": {
"title": "Winter hat",
"productOptions": [{"name"=>"Color", "position"=>1, "values"=>[{"name"=>"Grey"}, {"name"=>"Black"}]}],
"variants": [{"optionValues"=>[{"optionName"=>"Color", "name"=>"Grey"}], "price"=>79.99}, {"optionValues"=>[{"optionName"=>"Color", "name"=>"Black"}], "price"=>69.99}]
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "synchronous": false,3 "productSet": {4 "title": "Winter hat",5 "productOptions": [6 {7 "name": "Color",8 "position": 1,9 "values": [10 {11 "name": "Grey"12 },13 {14 "name": "Black"15 }16 ]17 }18 ],19 "variants": [20 {21 "optionValues": [22 {23 "optionName": "Color",24 "name": "Grey"25 }26 ],27 "price": 79.9928 },29 {30 "optionValues": [31 {32 "optionName": "Color",33 "name": "Black"34 }35 ],36 "price": 69.9937 }38 ]39 }40}
Response
JSON1{2 "productSet": {3 "product": null,4 "productSetOperation": {5 "id": "gid://shopify/ProductSetOperation/1010603773",6 "status": "CREATED",7 "userErrors": []8 },9 "userErrors": []10 }11}