Create a product and associate files
Description
Create a product and associate file attachments (like images or videos).
This example returns the product and its associated image files.
Query
mutation createProduct($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
media(first: 5) {
nodes {
id
alt
mediaContentType
status
}
}
variants(first: 5) {
nodes {
title
price
media(first: 5) {
nodes {
id
alt
mediaContentType
status
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"synchronous": true,
"productSet": {
"title": "Winter hat",
"productOptions": [
{
"name": "Color",
"values": [
{
"name": "Grey"
},
{
"name": "Black"
}
]
}
],
"files": [
{
"originalSource": "https://example.com/hats/grey-hat.jpg",
"alt": "An elegant grey hat",
"filename": "grey-hat.jpg",
"contentType": "IMAGE"
},
{
"originalSource": "https://example.com/hats/black-hat.jpg",
"alt": "An elegant black hat",
"filename": "black-hat.jpg",
"contentType": "IMAGE"
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Color",
"name": "Grey"
}
],
"file": {
"originalSource": "https://example.com/hats/grey-hat.jpg",
"alt": "An elegant grey hat",
"filename": "grey-hat.jpg",
"contentType": "IMAGE"
},
"price": 11.99
},
{
"optionValues": [
{
"optionName": "Color",
"name": "Black"
}
],
"file": {
"originalSource": "https://example.com/hats/black-hat.jpg",
"alt": "An elegant black hat",
"filename": "black-hat.jpg",
"contentType": "IMAGE"
},
"price": 11.99
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation createProduct($productSet: ProductSetInput!, $synchronous: Boolean!) { productSet(synchronous: $synchronous, input: $productSet) { product { id media(first: 5) { nodes { id alt mediaContentType status } } variants(first: 5) { nodes { title price media(first: 5) { nodes { id alt mediaContentType status } } } } } userErrors { field message } } }",
"variables": {
"synchronous": true,
"productSet": {
"title": "Winter hat",
"productOptions": [
{
"name": "Color",
"values": [
{
"name": "Grey"
},
{
"name": "Black"
}
]
}
],
"files": [
{
"originalSource": "https://example.com/hats/grey-hat.jpg",
"alt": "An elegant grey hat",
"filename": "grey-hat.jpg",
"contentType": "IMAGE"
},
{
"originalSource": "https://example.com/hats/black-hat.jpg",
"alt": "An elegant black hat",
"filename": "black-hat.jpg",
"contentType": "IMAGE"
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Color",
"name": "Grey"
}
],
"file": {
"originalSource": "https://example.com/hats/grey-hat.jpg",
"alt": "An elegant grey hat",
"filename": "grey-hat.jpg",
"contentType": "IMAGE"
},
"price": 11.99
},
{
"optionValues": [
{
"optionName": "Color",
"name": "Black"
}
],
"file": {
"originalSource": "https://example.com/hats/black-hat.jpg",
"alt": "An elegant black hat",
"filename": "black-hat.jpg",
"contentType": "IMAGE"
},
"price": 11.99
}
]
}
}
}'
Remix
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createProduct($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
media(first: 5) {
nodes {
id
alt
mediaContentType
status
}
}
variants(first: 5) {
nodes {
title
price
media(first: 5) {
nodes {
id
alt
mediaContentType
status
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"synchronous": true,
"productSet": {
"title": "Winter hat",
"productOptions": [
{
"name": "Color",
"values": [
{
"name": "Grey"
},
{
"name": "Black"
}
]
}
],
"files": [
{
"originalSource": "https://example.com/hats/grey-hat.jpg",
"alt": "An elegant grey hat",
"filename": "grey-hat.jpg",
"contentType": "IMAGE"
},
{
"originalSource": "https://example.com/hats/black-hat.jpg",
"alt": "An elegant black hat",
"filename": "black-hat.jpg",
"contentType": "IMAGE"
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Color",
"name": "Grey"
}
],
"file": {
"originalSource": "https://example.com/hats/grey-hat.jpg",
"alt": "An elegant grey hat",
"filename": "grey-hat.jpg",
"contentType": "IMAGE"
},
"price": 11.99
},
{
"optionValues": [
{
"optionName": "Color",
"name": "Black"
}
],
"file": {
"originalSource": "https://example.com/hats/black-hat.jpg",
"alt": "An elegant black hat",
"filename": "black-hat.jpg",
"contentType": "IMAGE"
},
"price": 11.99
}
]
}
},
},
);
const data = await response.json();
Ruby
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 createProduct($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
media(first: 5) {
nodes {
id
alt
mediaContentType
status
}
}
variants(first: 5) {
nodes {
title
price
media(first: 5) {
nodes {
id
alt
mediaContentType
status
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"synchronous": true,
"productSet": {
"title": "Winter hat",
"productOptions": [{"name"=>"Color", "values"=>[{"name"=>"Grey"}, {"name"=>"Black"}]}],
"files": [{"originalSource"=>"https://example.com/hats/grey-hat.jpg", "alt"=>"An elegant grey hat", "filename"=>"grey-hat.jpg", "contentType"=>"IMAGE"}, {"originalSource"=>"https://example.com/hats/black-hat.jpg", "alt"=>"An elegant black hat", "filename"=>"black-hat.jpg", "contentType"=>"IMAGE"}],
"variants": [{"optionValues"=>[{"optionName"=>"Color", "name"=>"Grey"}], "file"=>{"originalSource"=>"https://example.com/hats/grey-hat.jpg", "alt"=>"An elegant grey hat", "filename"=>"grey-hat.jpg", "contentType"=>"IMAGE"}, "price"=>11.99}, {"optionValues"=>[{"optionName"=>"Color", "name"=>"Black"}], "file"=>{"originalSource"=>"https://example.com/hats/black-hat.jpg", "alt"=>"An elegant black hat", "filename"=>"black-hat.jpg", "contentType"=>"IMAGE"}, "price"=>11.99}]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation createProduct($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
media(first: 5) {
nodes {
id
alt
mediaContentType
status
}
}
variants(first: 5) {
nodes {
title
price
media(first: 5) {
nodes {
id
alt
mediaContentType
status
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"synchronous": true,
"productSet": {
"title": "Winter hat",
"productOptions": [
{
"name": "Color",
"values": [
{
"name": "Grey"
},
{
"name": "Black"
}
]
}
],
"files": [
{
"originalSource": "https://example.com/hats/grey-hat.jpg",
"alt": "An elegant grey hat",
"filename": "grey-hat.jpg",
"contentType": "IMAGE"
},
{
"originalSource": "https://example.com/hats/black-hat.jpg",
"alt": "An elegant black hat",
"filename": "black-hat.jpg",
"contentType": "IMAGE"
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Color",
"name": "Grey"
}
],
"file": {
"originalSource": "https://example.com/hats/grey-hat.jpg",
"alt": "An elegant grey hat",
"filename": "grey-hat.jpg",
"contentType": "IMAGE"
},
"price": 11.99
},
{
"optionValues": [
{
"optionName": "Color",
"name": "Black"
}
],
"file": {
"originalSource": "https://example.com/hats/black-hat.jpg",
"alt": "An elegant black hat",
"filename": "black-hat.jpg",
"contentType": "IMAGE"
},
"price": 11.99
}
]
}
},
},
});
Response
{
"productSet": {
"product": {
"id": "gid://shopify/Product/1072481957",
"media": {
"nodes": [
{
"alt": "An elegant grey hat",
"mediaContentType": "IMAGE",
"status": "UPLOADED"
},
{
"alt": "An elegant black hat",
"mediaContentType": "IMAGE",
"status": "UPLOADED"
}
]
},
"variants": {
"nodes": [
{
"title": "Grey",
"price": "11.99",
"media": {
"nodes": [
{
"alt": "An elegant grey hat",
"mediaContentType": "IMAGE",
"status": "UPLOADED"
}
]
}
},
{
"title": "Black",
"price": "11.99",
"media": {
"nodes": [
{
"alt": "An elegant black hat",
"mediaContentType": "IMAGE",
"status": "UPLOADED"
}
]
}
}
]
}
},
"userErrors": []
}
}
Create a product with a complete set of attributes
Description
Create a product with all available attributes, including SEO settings, tags, metafields, options, and variants.
This example returns the specified attributes with their populated values.
Query
mutation createEntireProduct($input: ProductSetInput!, $productPreferences: ProductPreferencesInput, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $input, productPreferences: $productPreferences) {
product {
id
title
description
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
compareAtPrice
selectedOptions {
name
optionValue {
id
name
}
}
taxable
taxCode
barcode
inventoryPolicy
metafields(first: 5) {
nodes {
key
value
type
namespace
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"synchronous": true,
"input": {
"title": "Winter gloves",
"descriptionHtml": "Keep your hands toasty in the winter",
"handle": "winter-gloves",
"productType": "Apparel",
"tags": [
"winter",
"gloves",
"clothing"
],
"vendor": "The Fake Glove Co",
"status": "ACTIVE",
"collections": [
"gid://shopify/Collection/442946009",
"gid://shopify/Collection/1063001310",
"gid://shopify/Collection/793607630"
],
"metafields": [
{
"namespace": "custom",
"key": "sustainability",
"value": "Eco-friendly",
"type": "single_line_text_field"
},
{
"namespace": "custom",
"key": "certified",
"value": "false",
"type": "boolean"
}
],
"productOptions": [
{
"name": "Finger Style",
"position": 1,
"values": [
{
"name": "Standard"
},
{
"name": "Fingerless"
}
]
},
{
"name": "Outer Material",
"position": 2,
"values": [
{
"name": "100% Wool"
},
{
"name": "Wool Blend"
}
]
}
],
"variants": [
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 1,
"price": 15,
"compareAtPrice": 20,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Standard",
"optionName": "Finger Style"
},
{
"name": "100% Wool",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 2,
"price": 15,
"compareAtPrice": 20,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Standard",
"optionName": "Finger Style"
},
{
"name": "Wool Blend",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 3,
"price": 15,
"compareAtPrice": 20,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Fingerless",
"optionName": "Finger Style"
},
{
"name": "100% Wool",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 4,
"price": 15,
"compareAtPrice": 20,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Fingerless",
"optionName": "Finger Style"
},
{
"name": "Wool Blend",
"optionName": "Outer Material"
}
]
}
]
},
"productPreferences": {
"showSkuAndBarcode": true,
"showInternationalShipping": false
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation createEntireProduct($input: ProductSetInput!, $productPreferences: ProductPreferencesInput, $synchronous: Boolean!) { productSet(synchronous: $synchronous, input: $input, productPreferences: $productPreferences) { product { id title description options(first: 5) { name position optionValues { name } } variants(first: 5) { nodes { price compareAtPrice selectedOptions { name optionValue { id name } } taxable taxCode barcode inventoryPolicy metafields(first: 5) { nodes { key value type namespace } } } } } userErrors { field message } } }",
"variables": {
"synchronous": true,
"input": {
"title": "Winter gloves",
"descriptionHtml": "Keep your hands toasty in the winter",
"handle": "winter-gloves",
"productType": "Apparel",
"tags": [
"winter",
"gloves",
"clothing"
],
"vendor": "The Fake Glove Co",
"status": "ACTIVE",
"collections": [
"gid://shopify/Collection/442946009",
"gid://shopify/Collection/1063001310",
"gid://shopify/Collection/793607630"
],
"metafields": [
{
"namespace": "custom",
"key": "sustainability",
"value": "Eco-friendly",
"type": "single_line_text_field"
},
{
"namespace": "custom",
"key": "certified",
"value": "false",
"type": "boolean"
}
],
"productOptions": [
{
"name": "Finger Style",
"position": 1,
"values": [
{
"name": "Standard"
},
{
"name": "Fingerless"
}
]
},
{
"name": "Outer Material",
"position": 2,
"values": [
{
"name": "100% Wool"
},
{
"name": "Wool Blend"
}
]
}
],
"variants": [
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 1,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Standard",
"optionName": "Finger Style"
},
{
"name": "100% Wool",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 2,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Standard",
"optionName": "Finger Style"
},
{
"name": "Wool Blend",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 3,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Fingerless",
"optionName": "Finger Style"
},
{
"name": "100% Wool",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 4,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Fingerless",
"optionName": "Finger Style"
},
{
"name": "Wool Blend",
"optionName": "Outer Material"
}
]
}
]
},
"productPreferences": {
"showSkuAndBarcode": true,
"showInternationalShipping": false
}
}
}'
Remix
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createEntireProduct($input: ProductSetInput!, $productPreferences: ProductPreferencesInput, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $input, productPreferences: $productPreferences) {
product {
id
title
description
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
compareAtPrice
selectedOptions {
name
optionValue {
id
name
}
}
taxable
taxCode
barcode
inventoryPolicy
metafields(first: 5) {
nodes {
key
value
type
namespace
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"synchronous": true,
"input": {
"title": "Winter gloves",
"descriptionHtml": "Keep your hands toasty in the winter",
"handle": "winter-gloves",
"productType": "Apparel",
"tags": [
"winter",
"gloves",
"clothing"
],
"vendor": "The Fake Glove Co",
"status": "ACTIVE",
"collections": [
"gid://shopify/Collection/442946009",
"gid://shopify/Collection/1063001310",
"gid://shopify/Collection/793607630"
],
"metafields": [
{
"namespace": "custom",
"key": "sustainability",
"value": "Eco-friendly",
"type": "single_line_text_field"
},
{
"namespace": "custom",
"key": "certified",
"value": "false",
"type": "boolean"
}
],
"productOptions": [
{
"name": "Finger Style",
"position": 1,
"values": [
{
"name": "Standard"
},
{
"name": "Fingerless"
}
]
},
{
"name": "Outer Material",
"position": 2,
"values": [
{
"name": "100% Wool"
},
{
"name": "Wool Blend"
}
]
}
],
"variants": [
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 1,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Standard",
"optionName": "Finger Style"
},
{
"name": "100% Wool",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 2,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Standard",
"optionName": "Finger Style"
},
{
"name": "Wool Blend",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 3,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Fingerless",
"optionName": "Finger Style"
},
{
"name": "100% Wool",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 4,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Fingerless",
"optionName": "Finger Style"
},
{
"name": "Wool Blend",
"optionName": "Outer Material"
}
]
}
]
},
"productPreferences": {
"showSkuAndBarcode": true,
"showInternationalShipping": false
}
},
},
);
const data = await response.json();
Ruby
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 createEntireProduct($input: ProductSetInput!, $productPreferences: ProductPreferencesInput, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $input, productPreferences: $productPreferences) {
product {
id
title
description
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
compareAtPrice
selectedOptions {
name
optionValue {
id
name
}
}
taxable
taxCode
barcode
inventoryPolicy
metafields(first: 5) {
nodes {
key
value
type
namespace
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"synchronous": true,
"input": {
"title": "Winter gloves",
"descriptionHtml": "Keep your hands toasty in the winter",
"handle": "winter-gloves",
"productType": "Apparel",
"tags": ["winter", "gloves", "clothing"],
"vendor": "The Fake Glove Co",
"status": "ACTIVE",
"collections": ["gid://shopify/Collection/442946009", "gid://shopify/Collection/1063001310", "gid://shopify/Collection/793607630"],
"metafields": [{"namespace"=>"custom", "key"=>"sustainability", "value"=>"Eco-friendly", "type"=>"single_line_text_field"}, {"namespace"=>"custom", "key"=>"certified", "value"=>"false", "type"=>"boolean"}],
"productOptions": [{"name"=>"Finger Style", "position"=>1, "values"=>[{"name"=>"Standard"}, {"name"=>"Fingerless"}]}, {"name"=>"Outer Material", "position"=>2, "values"=>[{"name"=>"100% Wool"}, {"name"=>"Wool Blend"}]}],
"variants": [{"requiresComponents"=>false, "barcode"=>"ABC-abc-1234", "inventoryPolicy"=>"DENY", "position"=>1, "price"=>15.0, "compareAtPrice"=>20.0, "taxable"=>true, "taxCode"=>"ZER", "metafields"=>[{"namespace"=>"custom", "key"=>"sustainability_rating", "value"=>"4.5", "type"=>"float"}, {"namespace"=>"custom", "key"=>"origin_country", "value"=>"CN", "type"=>"single_line_text_field"}], "optionValues"=>[{"name"=>"Standard", "optionName"=>"Finger Style"}, {"name"=>"100% Wool", "optionName"=>"Outer Material"}]}, {"requiresComponents"=>false, "barcode"=>"ABC-abc-1234", "inventoryPolicy"=>"DENY", "position"=>2, "price"=>15.0, "compareAtPrice"=>20.0, "taxable"=>true, "taxCode"=>"ZER", "metafields"=>[{"namespace"=>"custom", "key"=>"sustainability_rating", "value"=>"4.5", "type"=>"float"}, {"namespace"=>"custom", "key"=>"origin_country", "value"=>"CN", "type"=>"single_line_text_field"}], "optionValues"=>[{"name"=>"Standard", "optionName"=>"Finger Style"}, {"name"=>"Wool Blend", "optionName"=>"Outer Material"}]}, {"requiresComponents"=>false, "barcode"=>"ABC-abc-1234", "inventoryPolicy"=>"DENY", "position"=>3, "price"=>15.0, "compareAtPrice"=>20.0, "taxable"=>true, "taxCode"=>"ZER", "metafields"=>[{"namespace"=>"custom", "key"=>"sustainability_rating", "value"=>"4.5", "type"=>"float"}, {"namespace"=>"custom", "key"=>"origin_country", "value"=>"CN", "type"=>"single_line_text_field"}], "optionValues"=>[{"name"=>"Fingerless", "optionName"=>"Finger Style"}, {"name"=>"100% Wool", "optionName"=>"Outer Material"}]}, {"requiresComponents"=>false, "barcode"=>"ABC-abc-1234", "inventoryPolicy"=>"DENY", "position"=>4, "price"=>15.0, "compareAtPrice"=>20.0, "taxable"=>true, "taxCode"=>"ZER", "metafields"=>[{"namespace"=>"custom", "key"=>"sustainability_rating", "value"=>"4.5", "type"=>"float"}, {"namespace"=>"custom", "key"=>"origin_country", "value"=>"CN", "type"=>"single_line_text_field"}], "optionValues"=>[{"name"=>"Fingerless", "optionName"=>"Finger Style"}, {"name"=>"Wool Blend", "optionName"=>"Outer Material"}]}]
},
"productPreferences": {
"showSkuAndBarcode": true,
"showInternationalShipping": false
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation createEntireProduct($input: ProductSetInput!, $productPreferences: ProductPreferencesInput, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $input, productPreferences: $productPreferences) {
product {
id
title
description
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
compareAtPrice
selectedOptions {
name
optionValue {
id
name
}
}
taxable
taxCode
barcode
inventoryPolicy
metafields(first: 5) {
nodes {
key
value
type
namespace
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"synchronous": true,
"input": {
"title": "Winter gloves",
"descriptionHtml": "Keep your hands toasty in the winter",
"handle": "winter-gloves",
"productType": "Apparel",
"tags": [
"winter",
"gloves",
"clothing"
],
"vendor": "The Fake Glove Co",
"status": "ACTIVE",
"collections": [
"gid://shopify/Collection/442946009",
"gid://shopify/Collection/1063001310",
"gid://shopify/Collection/793607630"
],
"metafields": [
{
"namespace": "custom",
"key": "sustainability",
"value": "Eco-friendly",
"type": "single_line_text_field"
},
{
"namespace": "custom",
"key": "certified",
"value": "false",
"type": "boolean"
}
],
"productOptions": [
{
"name": "Finger Style",
"position": 1,
"values": [
{
"name": "Standard"
},
{
"name": "Fingerless"
}
]
},
{
"name": "Outer Material",
"position": 2,
"values": [
{
"name": "100% Wool"
},
{
"name": "Wool Blend"
}
]
}
],
"variants": [
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 1,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Standard",
"optionName": "Finger Style"
},
{
"name": "100% Wool",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 2,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Standard",
"optionName": "Finger Style"
},
{
"name": "Wool Blend",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 3,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Fingerless",
"optionName": "Finger Style"
},
{
"name": "100% Wool",
"optionName": "Outer Material"
}
]
},
{
"requiresComponents": false,
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"position": 4,
"price": 15.0,
"compareAtPrice": 20.0,
"taxable": true,
"taxCode": "ZER",
"metafields": [
{
"namespace": "custom",
"key": "sustainability_rating",
"value": "4.5",
"type": "float"
},
{
"namespace": "custom",
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field"
}
],
"optionValues": [
{
"name": "Fingerless",
"optionName": "Finger Style"
},
{
"name": "Wool Blend",
"optionName": "Outer Material"
}
]
}
]
},
"productPreferences": {
"showSkuAndBarcode": true,
"showInternationalShipping": false
}
},
},
});
Response
{
"productSet": {
"product": {
"id": "gid://shopify/Product/1072481963",
"title": "Winter gloves",
"description": "Keep your hands toasty in the winter",
"options": [
{
"name": "Finger Style",
"position": 1,
"optionValues": [
{
"name": "Standard"
},
{
"name": "Fingerless"
}
]
},
{
"name": "Outer Material",
"position": 2,
"optionValues": [
{
"name": "100% Wool"
},
{
"name": "Wool Blend"
}
]
}
],
"variants": {
"nodes": [
{
"price": "15.00",
"compareAtPrice": "20.00",
"selectedOptions": [
{
"name": "Finger Style",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677241",
"name": "Standard"
}
},
{
"name": "Outer Material",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677243",
"name": "100% Wool"
}
}
],
"taxable": true,
"taxCode": "ZER",
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"metafields": {
"nodes": [
{
"key": "sustainability_rating",
"value": "4.5",
"type": "float",
"namespace": "custom"
},
{
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field",
"namespace": "custom"
}
]
}
},
{
"price": "15.00",
"compareAtPrice": "20.00",
"selectedOptions": [
{
"name": "Finger Style",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677241",
"name": "Standard"
}
},
{
"name": "Outer Material",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677244",
"name": "Wool Blend"
}
}
],
"taxable": true,
"taxCode": "ZER",
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"metafields": {
"nodes": [
{
"key": "sustainability_rating",
"value": "4.5",
"type": "float",
"namespace": "custom"
},
{
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field",
"namespace": "custom"
}
]
}
},
{
"price": "15.00",
"compareAtPrice": "20.00",
"selectedOptions": [
{
"name": "Finger Style",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677242",
"name": "Fingerless"
}
},
{
"name": "Outer Material",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677243",
"name": "100% Wool"
}
}
],
"taxable": true,
"taxCode": "ZER",
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"metafields": {
"nodes": [
{
"key": "sustainability_rating",
"value": "4.5",
"type": "float",
"namespace": "custom"
},
{
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field",
"namespace": "custom"
}
]
}
},
{
"price": "15.00",
"compareAtPrice": "20.00",
"selectedOptions": [
{
"name": "Finger Style",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677242",
"name": "Fingerless"
}
},
{
"name": "Outer Material",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677244",
"name": "Wool Blend"
}
}
],
"taxable": true,
"taxCode": "ZER",
"barcode": "ABC-abc-1234",
"inventoryPolicy": "DENY",
"metafields": {
"nodes": [
{
"key": "sustainability_rating",
"value": "4.5",
"type": "float",
"namespace": "custom"
},
{
"key": "origin_country",
"value": "CN",
"type": "single_line_text_field",
"namespace": "custom"
}
]
}
}
]
}
},
"userErrors": []
}
}
Create a product with customized inventory quantities
Description
Create a product with [inventory quantities](https://shopify.dev/docs/apps/build/orders-fulfillment/inventory-management-apps/manage-quantities-states).
This example returns the product with the specified inventory quantities configured for the variants.
Query
mutation createProduct($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
variants(first: 5) {
nodes {
title
price
inventoryQuantity
inventoryItem {
inventoryLevels(first: 5) {
nodes {
location {
id
name
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"synchronous": true,
"productSet": {
"title": "Winter hat",
"productOptions": [
{
"name": "Color",
"position": 1,
"values": [
{
"name": "Grey"
},
{
"name": "Black"
}
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Color",
"name": "Grey"
}
],
"inventoryQuantities": [
{
"locationId": "gid://shopify/Location/415211365",
"name": "available",
"quantity": 12
},
{
"locationId": "gid://shopify/Location/346779380",
"name": "available",
"quantity": 19
}
],
"price": 79.99
},
{
"optionValues": [
{
"optionName": "Color",
"name": "Black"
}
],
"inventoryQuantities": [
{
"locationId": "gid://shopify/Location/346779380",
"name": "available",
"quantity": 976
},
{
"locationId": "gid://shopify/Location/415211365",
"name": "available",
"quantity": 844
}
],
"price": 11.99
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation createProduct($productSet: ProductSetInput!, $synchronous: Boolean!) { productSet(synchronous: $synchronous, input: $productSet) { product { id variants(first: 5) { nodes { title price inventoryQuantity inventoryItem { inventoryLevels(first: 5) { nodes { location { id name } } } } } } } userErrors { field message } } }",
"variables": {
"synchronous": true,
"productSet": {
"title": "Winter hat",
"productOptions": [
{
"name": "Color",
"position": 1,
"values": [
{
"name": "Grey"
},
{
"name": "Black"
}
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Color",
"name": "Grey"
}
],
"inventoryQuantities": [
{
"locationId": "gid://shopify/Location/415211365",
"name": "available",
"quantity": 12
},
{
"locationId": "gid://shopify/Location/346779380",
"name": "available",
"quantity": 19
}
],
"price": 79.99
},
{
"optionValues": [
{
"optionName": "Color",
"name": "Black"
}
],
"inventoryQuantities": [
{
"locationId": "gid://shopify/Location/346779380",
"name": "available",
"quantity": 976
},
{
"locationId": "gid://shopify/Location/415211365",
"name": "available",
"quantity": 844
}
],
"price": 11.99
}
]
}
}
}'
Remix
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createProduct($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
variants(first: 5) {
nodes {
title
price
inventoryQuantity
inventoryItem {
inventoryLevels(first: 5) {
nodes {
location {
id
name
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"synchronous": true,
"productSet": {
"title": "Winter hat",
"productOptions": [
{
"name": "Color",
"position": 1,
"values": [
{
"name": "Grey"
},
{
"name": "Black"
}
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Color",
"name": "Grey"
}
],
"inventoryQuantities": [
{
"locationId": "gid://shopify/Location/415211365",
"name": "available",
"quantity": 12
},
{
"locationId": "gid://shopify/Location/346779380",
"name": "available",
"quantity": 19
}
],
"price": 79.99
},
{
"optionValues": [
{
"optionName": "Color",
"name": "Black"
}
],
"inventoryQuantities": [
{
"locationId": "gid://shopify/Location/346779380",
"name": "available",
"quantity": 976
},
{
"locationId": "gid://shopify/Location/415211365",
"name": "available",
"quantity": 844
}
],
"price": 11.99
}
]
}
},
},
);
const data = await response.json();
Ruby
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 createProduct($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
variants(first: 5) {
nodes {
title
price
inventoryQuantity
inventoryItem {
inventoryLevels(first: 5) {
nodes {
location {
id
name
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"synchronous": true,
"productSet": {
"title": "Winter hat",
"productOptions": [{"name"=>"Color", "position"=>1, "values"=>[{"name"=>"Grey"}, {"name"=>"Black"}]}],
"variants": [{"optionValues"=>[{"optionName"=>"Color", "name"=>"Grey"}], "inventoryQuantities"=>[{"locationId"=>"gid://shopify/Location/415211365", "name"=>"available", "quantity"=>12}, {"locationId"=>"gid://shopify/Location/346779380", "name"=>"available", "quantity"=>19}], "price"=>79.99}, {"optionValues"=>[{"optionName"=>"Color", "name"=>"Black"}], "inventoryQuantities"=>[{"locationId"=>"gid://shopify/Location/346779380", "name"=>"available", "quantity"=>976}, {"locationId"=>"gid://shopify/Location/415211365", "name"=>"available", "quantity"=>844}], "price"=>11.99}]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation createProduct($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
variants(first: 5) {
nodes {
title
price
inventoryQuantity
inventoryItem {
inventoryLevels(first: 5) {
nodes {
location {
id
name
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"synchronous": true,
"productSet": {
"title": "Winter hat",
"productOptions": [
{
"name": "Color",
"position": 1,
"values": [
{
"name": "Grey"
},
{
"name": "Black"
}
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Color",
"name": "Grey"
}
],
"inventoryQuantities": [
{
"locationId": "gid://shopify/Location/415211365",
"name": "available",
"quantity": 12
},
{
"locationId": "gid://shopify/Location/346779380",
"name": "available",
"quantity": 19
}
],
"price": 79.99
},
{
"optionValues": [
{
"optionName": "Color",
"name": "Black"
}
],
"inventoryQuantities": [
{
"locationId": "gid://shopify/Location/346779380",
"name": "available",
"quantity": 976
},
{
"locationId": "gid://shopify/Location/415211365",
"name": "available",
"quantity": 844
}
],
"price": 11.99
}
]
}
},
},
});
Response
{
"productSet": {
"product": {
"id": "gid://shopify/Product/1072481937",
"variants": {
"nodes": [
{
"title": "Grey",
"price": "79.99",
"inventoryQuantity": 31,
"inventoryItem": {
"inventoryLevels": {
"nodes": [
{
"location": {
"id": "gid://shopify/Location/346779380",
"name": "Ottawa Store"
}
},
{
"location": {
"id": "gid://shopify/Location/415211365",
"name": "US Store"
}
}
]
}
}
},
{
"title": "Black",
"price": "11.99",
"inventoryQuantity": 1820,
"inventoryItem": {
"inventoryLevels": {
"nodes": [
{
"location": {
"id": "gid://shopify/Location/346779380",
"name": "Ottawa Store"
}
},
{
"location": {
"id": "gid://shopify/Location/415211365",
"name": "US Store"
}
}
]
}
}
}
]
}
},
"userErrors": []
}
}
Create a product with two options and four variants
Description
Create a product with [multiple options](https://shopify.dev/docs/api/admin-graphql/latest/objects/ProductOption)
and all possible [variant](https://shopify.dev/docs/api/admin-graphql/latest/objects/ProductVariant) combinations.
This example returns a product with two options and four variants, representing all
[option value](https://shopify.dev/docs/api/admin-graphql/latest/objects/ProductOptionValue) combinations.
Query
mutation createProductWithTwoOptionsAndVariants($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
title
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
selectedOptions {
name
optionValue {
id
name
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"synchronous": true,
"productSet": {
"title": "A humble tie",
"productOptions": [
{
"name": "Pattern",
"position": 1,
"values": [
{
"name": "Plain"
},
{
"name": "Stripes"
}
]
},
{
"name": "Width",
"position": 2,
"values": [
{
"name": "Slim"
},
{
"name": "Classic"
}
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Plain"
},
{
"optionName": "Width",
"name": "Slim"
}
],
"price": 15
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Plain"
},
{
"optionName": "Width",
"name": "Classic"
}
],
"price": 15
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Stripes"
},
{
"optionName": "Width",
"name": "Slim"
}
],
"price": 15
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Stripes"
},
{
"optionName": "Width",
"name": "Classic"
}
],
"price": 15
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation createProductWithTwoOptionsAndVariants($productSet: ProductSetInput!, $synchronous: Boolean!) { productSet(synchronous: $synchronous, input: $productSet) { product { id title options(first: 5) { name position optionValues { name } } variants(first: 5) { nodes { price selectedOptions { name optionValue { id name } } } } } userErrors { field message } } }",
"variables": {
"synchronous": true,
"productSet": {
"title": "A humble tie",
"productOptions": [
{
"name": "Pattern",
"position": 1,
"values": [
{
"name": "Plain"
},
{
"name": "Stripes"
}
]
},
{
"name": "Width",
"position": 2,
"values": [
{
"name": "Slim"
},
{
"name": "Classic"
}
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Plain"
},
{
"optionName": "Width",
"name": "Slim"
}
],
"price": 15.0
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Plain"
},
{
"optionName": "Width",
"name": "Classic"
}
],
"price": 15.0
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Stripes"
},
{
"optionName": "Width",
"name": "Slim"
}
],
"price": 15.0
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Stripes"
},
{
"optionName": "Width",
"name": "Classic"
}
],
"price": 15.0
}
]
}
}
}'
Remix
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createProductWithTwoOptionsAndVariants($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
title
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
selectedOptions {
name
optionValue {
id
name
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"synchronous": true,
"productSet": {
"title": "A humble tie",
"productOptions": [
{
"name": "Pattern",
"position": 1,
"values": [
{
"name": "Plain"
},
{
"name": "Stripes"
}
]
},
{
"name": "Width",
"position": 2,
"values": [
{
"name": "Slim"
},
{
"name": "Classic"
}
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Plain"
},
{
"optionName": "Width",
"name": "Slim"
}
],
"price": 15.0
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Plain"
},
{
"optionName": "Width",
"name": "Classic"
}
],
"price": 15.0
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Stripes"
},
{
"optionName": "Width",
"name": "Slim"
}
],
"price": 15.0
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Stripes"
},
{
"optionName": "Width",
"name": "Classic"
}
],
"price": 15.0
}
]
}
},
},
);
const data = await response.json();
Ruby
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 createProductWithTwoOptionsAndVariants($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
title
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
selectedOptions {
name
optionValue {
id
name
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"synchronous": true,
"productSet": {
"title": "A humble tie",
"productOptions": [{"name"=>"Pattern", "position"=>1, "values"=>[{"name"=>"Plain"}, {"name"=>"Stripes"}]}, {"name"=>"Width", "position"=>2, "values"=>[{"name"=>"Slim"}, {"name"=>"Classic"}]}],
"variants": [{"optionValues"=>[{"optionName"=>"Pattern", "name"=>"Plain"}, {"optionName"=>"Width", "name"=>"Slim"}], "price"=>15.0}, {"optionValues"=>[{"optionName"=>"Pattern", "name"=>"Plain"}, {"optionName"=>"Width", "name"=>"Classic"}], "price"=>15.0}, {"optionValues"=>[{"optionName"=>"Pattern", "name"=>"Stripes"}, {"optionName"=>"Width", "name"=>"Slim"}], "price"=>15.0}, {"optionValues"=>[{"optionName"=>"Pattern", "name"=>"Stripes"}, {"optionName"=>"Width", "name"=>"Classic"}], "price"=>15.0}]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation createProductWithTwoOptionsAndVariants($productSet: ProductSetInput!, $synchronous: Boolean!) {
productSet(synchronous: $synchronous, input: $productSet) {
product {
id
title
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
selectedOptions {
name
optionValue {
id
name
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"synchronous": true,
"productSet": {
"title": "A humble tie",
"productOptions": [
{
"name": "Pattern",
"position": 1,
"values": [
{
"name": "Plain"
},
{
"name": "Stripes"
}
]
},
{
"name": "Width",
"position": 2,
"values": [
{
"name": "Slim"
},
{
"name": "Classic"
}
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Plain"
},
{
"optionName": "Width",
"name": "Slim"
}
],
"price": 15.0
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Plain"
},
{
"optionName": "Width",
"name": "Classic"
}
],
"price": 15.0
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Stripes"
},
{
"optionName": "Width",
"name": "Slim"
}
],
"price": 15.0
},
{
"optionValues": [
{
"optionName": "Pattern",
"name": "Stripes"
},
{
"optionName": "Width",
"name": "Classic"
}
],
"price": 15.0
}
]
}
},
},
});
Response
{
"productSet": {
"product": {
"id": "gid://shopify/Product/1072481953",
"title": "A humble tie",
"options": [
{
"name": "Pattern",
"position": 1,
"optionValues": [
{
"name": "Plain"
},
{
"name": "Stripes"
}
]
},
{
"name": "Width",
"position": 2,
"optionValues": [
{
"name": "Slim"
},
{
"name": "Classic"
}
]
}
],
"variants": {
"nodes": [
{
"price": "15.00",
"selectedOptions": [
{
"name": "Pattern",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677147",
"name": "Plain"
}
},
{
"name": "Width",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677149",
"name": "Slim"
}
}
]
},
{
"price": "15.00",
"selectedOptions": [
{
"name": "Pattern",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677147",
"name": "Plain"
}
},
{
"name": "Width",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677150",
"name": "Classic"
}
}
]
},
{
"price": "15.00",
"selectedOptions": [
{
"name": "Pattern",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677148",
"name": "Stripes"
}
},
{
"name": "Width",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677149",
"name": "Slim"
}
}
]
},
{
"price": "15.00",
"selectedOptions": [
{
"name": "Pattern",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677148",
"name": "Stripes"
}
},
{
"name": "Width",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054677150",
"name": "Classic"
}
}
]
}
]
}
},
"userErrors": []
}
}
Update the price of variants by IDs
Description
Update the price of variants using their IDs.
This example returns the updated variant pricing, while maintaining the existing options and variants.
Query
mutation updateProductVariantPricing($input: ProductSetInput!, $synchronous: Boolean!, $identifier: ProductSetIdentifiers) {
productSet(synchronous: $synchronous, input: $input, identifier: $identifier) {
product {
id
title
description
handle
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
compareAtPrice
selectedOptions {
name
optionValue {
id
name
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"synchronous": true,
"identifier": {
"id": "gid://shopify/Product/1072481936"
},
"input": {
"title": "Bike frame",
"descriptionHtml": "Blending durability with aerodynamics",
"handle": "bike-frame",
"productType": "parts",
"tags": [
"cycling",
"bike",
"parts"
],
"vendor": "Your cycling company",
"status": "ACTIVE",
"productOptions": [
{
"id": "gid://shopify/ProductOption/1064578002",
"values": [
{
"id": "gid://shopify/ProductOptionValue/1054676956"
},
{
"id": "gid://shopify/ProductOptionValue/1054676957"
},
{
"id": "gid://shopify/ProductOptionValue/1054676958"
}
]
},
{
"id": "gid://shopify/ProductOption/1064578003",
"values": [
{
"id": "gid://shopify/ProductOptionValue/1054676960"
},
{
"id": "gid://shopify/ProductOptionValue/1054676959"
},
{
"id": "gid://shopify/ProductOptionValue/1054676961"
}
]
}
],
"variants": [
{
"id": "gid://shopify/ProductVariant/1070328469",
"position": 1,
"price": 94.99,
"compareAtPrice": 99.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676956",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676959",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
},
{
"id": "gid://shopify/ProductVariant/1070328470",
"position": 2,
"price": 259.99,
"compareAtPrice": 299.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676957",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676960",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
},
{
"id": "gid://shopify/ProductVariant/1070328471",
"position": 3,
"price": 169.99,
"compareAtPrice": 199.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676958",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676961",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation updateProductVariantPricing($input: ProductSetInput!, $synchronous: Boolean!, $identifier: ProductSetIdentifiers) { productSet(synchronous: $synchronous, input: $input, identifier: $identifier) { product { id title description handle options(first: 5) { name position optionValues { name } } variants(first: 5) { nodes { price compareAtPrice selectedOptions { name optionValue { id name } } } } } userErrors { field message } } }",
"variables": {
"synchronous": true,
"identifier": {
"id": "gid://shopify/Product/1072481936"
},
"input": {
"title": "Bike frame",
"descriptionHtml": "Blending durability with aerodynamics",
"handle": "bike-frame",
"productType": "parts",
"tags": [
"cycling",
"bike",
"parts"
],
"vendor": "Your cycling company",
"status": "ACTIVE",
"productOptions": [
{
"id": "gid://shopify/ProductOption/1064578002",
"values": [
{
"id": "gid://shopify/ProductOptionValue/1054676956"
},
{
"id": "gid://shopify/ProductOptionValue/1054676957"
},
{
"id": "gid://shopify/ProductOptionValue/1054676958"
}
]
},
{
"id": "gid://shopify/ProductOption/1064578003",
"values": [
{
"id": "gid://shopify/ProductOptionValue/1054676960"
},
{
"id": "gid://shopify/ProductOptionValue/1054676959"
},
{
"id": "gid://shopify/ProductOptionValue/1054676961"
}
]
}
],
"variants": [
{
"id": "gid://shopify/ProductVariant/1070328469",
"position": 1,
"price": 94.99,
"compareAtPrice": 99.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676956",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676959",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
},
{
"id": "gid://shopify/ProductVariant/1070328470",
"position": 2,
"price": 259.99,
"compareAtPrice": 299.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676957",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676960",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
},
{
"id": "gid://shopify/ProductVariant/1070328471",
"position": 3,
"price": 169.99,
"compareAtPrice": 199.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676958",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676961",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
}
]
}
}
}'
Remix
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation updateProductVariantPricing($input: ProductSetInput!, $synchronous: Boolean!, $identifier: ProductSetIdentifiers) {
productSet(synchronous: $synchronous, input: $input, identifier: $identifier) {
product {
id
title
description
handle
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
compareAtPrice
selectedOptions {
name
optionValue {
id
name
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"synchronous": true,
"identifier": {
"id": "gid://shopify/Product/1072481936"
},
"input": {
"title": "Bike frame",
"descriptionHtml": "Blending durability with aerodynamics",
"handle": "bike-frame",
"productType": "parts",
"tags": [
"cycling",
"bike",
"parts"
],
"vendor": "Your cycling company",
"status": "ACTIVE",
"productOptions": [
{
"id": "gid://shopify/ProductOption/1064578002",
"values": [
{
"id": "gid://shopify/ProductOptionValue/1054676956"
},
{
"id": "gid://shopify/ProductOptionValue/1054676957"
},
{
"id": "gid://shopify/ProductOptionValue/1054676958"
}
]
},
{
"id": "gid://shopify/ProductOption/1064578003",
"values": [
{
"id": "gid://shopify/ProductOptionValue/1054676960"
},
{
"id": "gid://shopify/ProductOptionValue/1054676959"
},
{
"id": "gid://shopify/ProductOptionValue/1054676961"
}
]
}
],
"variants": [
{
"id": "gid://shopify/ProductVariant/1070328469",
"position": 1,
"price": 94.99,
"compareAtPrice": 99.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676956",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676959",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
},
{
"id": "gid://shopify/ProductVariant/1070328470",
"position": 2,
"price": 259.99,
"compareAtPrice": 299.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676957",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676960",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
},
{
"id": "gid://shopify/ProductVariant/1070328471",
"position": 3,
"price": 169.99,
"compareAtPrice": 199.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676958",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676961",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
}
]
}
},
},
);
const data = await response.json();
Ruby
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 updateProductVariantPricing($input: ProductSetInput!, $synchronous: Boolean!, $identifier: ProductSetIdentifiers) {
productSet(synchronous: $synchronous, input: $input, identifier: $identifier) {
product {
id
title
description
handle
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
compareAtPrice
selectedOptions {
name
optionValue {
id
name
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"synchronous": true,
"identifier": {
"id": "gid://shopify/Product/1072481936"
},
"input": {
"title": "Bike frame",
"descriptionHtml": "Blending durability with aerodynamics",
"handle": "bike-frame",
"productType": "parts",
"tags": ["cycling", "bike", "parts"],
"vendor": "Your cycling company",
"status": "ACTIVE",
"productOptions": [{"id"=>"gid://shopify/ProductOption/1064578002", "values"=>[{"id"=>"gid://shopify/ProductOptionValue/1054676956"}, {"id"=>"gid://shopify/ProductOptionValue/1054676957"}, {"id"=>"gid://shopify/ProductOptionValue/1054676958"}]}, {"id"=>"gid://shopify/ProductOption/1064578003", "values"=>[{"id"=>"gid://shopify/ProductOptionValue/1054676960"}, {"id"=>"gid://shopify/ProductOptionValue/1054676959"}, {"id"=>"gid://shopify/ProductOptionValue/1054676961"}]}],
"variants": [{"id"=>"gid://shopify/ProductVariant/1070328469", "position"=>1, "price"=>94.99, "compareAtPrice"=>99.99, "optionValues"=>[{"id"=>"gid://shopify/ProductOptionValue/1054676956", "optionId"=>"gid://shopify/ProductOption/1064578002"}, {"id"=>"gid://shopify/ProductOptionValue/1054676959", "optionId"=>"gid://shopify/ProductOption/1064578003"}]}, {"id"=>"gid://shopify/ProductVariant/1070328470", "position"=>2, "price"=>259.99, "compareAtPrice"=>299.99, "optionValues"=>[{"id"=>"gid://shopify/ProductOptionValue/1054676957", "optionId"=>"gid://shopify/ProductOption/1064578002"}, {"id"=>"gid://shopify/ProductOptionValue/1054676960", "optionId"=>"gid://shopify/ProductOption/1064578003"}]}, {"id"=>"gid://shopify/ProductVariant/1070328471", "position"=>3, "price"=>169.99, "compareAtPrice"=>199.99, "optionValues"=>[{"id"=>"gid://shopify/ProductOptionValue/1054676958", "optionId"=>"gid://shopify/ProductOption/1064578002"}, {"id"=>"gid://shopify/ProductOptionValue/1054676961", "optionId"=>"gid://shopify/ProductOption/1064578003"}]}]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation updateProductVariantPricing($input: ProductSetInput!, $synchronous: Boolean!, $identifier: ProductSetIdentifiers) {
productSet(synchronous: $synchronous, input: $input, identifier: $identifier) {
product {
id
title
description
handle
options(first: 5) {
name
position
optionValues {
name
}
}
variants(first: 5) {
nodes {
price
compareAtPrice
selectedOptions {
name
optionValue {
id
name
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"synchronous": true,
"identifier": {
"id": "gid://shopify/Product/1072481936"
},
"input": {
"title": "Bike frame",
"descriptionHtml": "Blending durability with aerodynamics",
"handle": "bike-frame",
"productType": "parts",
"tags": [
"cycling",
"bike",
"parts"
],
"vendor": "Your cycling company",
"status": "ACTIVE",
"productOptions": [
{
"id": "gid://shopify/ProductOption/1064578002",
"values": [
{
"id": "gid://shopify/ProductOptionValue/1054676956"
},
{
"id": "gid://shopify/ProductOptionValue/1054676957"
},
{
"id": "gid://shopify/ProductOptionValue/1054676958"
}
]
},
{
"id": "gid://shopify/ProductOption/1064578003",
"values": [
{
"id": "gid://shopify/ProductOptionValue/1054676960"
},
{
"id": "gid://shopify/ProductOptionValue/1054676959"
},
{
"id": "gid://shopify/ProductOptionValue/1054676961"
}
]
}
],
"variants": [
{
"id": "gid://shopify/ProductVariant/1070328469",
"position": 1,
"price": 94.99,
"compareAtPrice": 99.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676956",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676959",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
},
{
"id": "gid://shopify/ProductVariant/1070328470",
"position": 2,
"price": 259.99,
"compareAtPrice": 299.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676957",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676960",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
},
{
"id": "gid://shopify/ProductVariant/1070328471",
"position": 3,
"price": 169.99,
"compareAtPrice": 199.99,
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/1054676958",
"optionId": "gid://shopify/ProductOption/1064578002"
},
{
"id": "gid://shopify/ProductOptionValue/1054676961",
"optionId": "gid://shopify/ProductOption/1064578003"
}
]
}
]
}
},
},
});
Response
{
"productSet": {
"product": {
"id": "gid://shopify/Product/1072481936",
"title": "Bike frame",
"description": "Blending durability with aerodynamics",
"handle": "bike-frame",
"options": [
{
"name": "Material",
"position": 1,
"optionValues": [
{
"name": "Aluminium"
},
{
"name": "Carbon"
},
{
"name": "Steel"
}
]
},
{
"name": "Color",
"position": 2,
"optionValues": [
{
"name": "Grey"
},
{
"name": "Black"
},
{
"name": "Silver"
}
]
}
],
"variants": {
"nodes": [
{
"price": "94.99",
"compareAtPrice": "99.99",
"selectedOptions": [
{
"name": "Material",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054676956",
"name": "Aluminium"
}
},
{
"name": "Color",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054676959",
"name": "Grey"
}
}
]
},
{
"price": "259.99",
"compareAtPrice": "299.99",
"selectedOptions": [
{
"name": "Material",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054676957",
"name": "Carbon"
}
},
{
"name": "Color",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054676960",
"name": "Black"
}
}
]
},
{
"price": "169.99",
"compareAtPrice": "199.99",
"selectedOptions": [
{
"name": "Material",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054676958",
"name": "Steel"
}
},
{
"name": "Color",
"optionValue": {
"id": "gid://shopify/ProductOptionValue/1054676961",
"name": "Silver"
}
}
]
}
]
}
},
"userErrors": []
}
}