A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
userErrors {
field
message
}
shop {
id
}
product {
title
handle
variants {
edges {
node {
title
}
}
}
}
}
}
{
"input": {
"title": "Testing Products",
"handle": "test-product-2",
"variants": [
{ "title": "Variant 1" },
{ "title": "Variant 2" }
]
}
}
{
"data": {
"productCreate": {
"userErrors": [
{
"field": [
"variants",
"1"
],
"message": "The variant 'Default Title' already exists."
}
],
"shop": {
"id": "gid://shopify/Shop/59898691733"
},
"product": null
}
},
"extensions": {
"cost": {
"requestedQueryCost": 12,
"actualQueryCost": 10,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 990,
"restoreRate": 50
}
}
}
}
Solved! Go to the solution
This is an accepted solution.
Hey @MrGuvna,
Just wanted to expand on what was shared by @VivekH and a pass on a few more insights.
The "title" field in the "variants" input (ProductVariantInput.title - documentation here) is deprecated, and not a writeable field at this time. Instead, this is generated from the variant input "options" field - options must be a string for example: small, medium, red, blue, 50g, 100g etc.
Below is a mutation and input I used to create a product with multiple variants - Cheers!
EXAMPLE REQUEST:
mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
shop {
id
}
userErrors {
field
message
}
product {
id
variants(first: 5) {
edges {
node {
id
title
barcode
}
}
}
}
}
}
{
"input": {
"title": "New Product",
"variants":[
{
"barcode": "654321",
"options": "V.1"
},
{
"barcode": "765432",
"options": "V.2"
}
]
}
}
awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi,
Try with this json instead
{"input": {"title": "Testing Products","handle": "test-product-2","variants": [{"sku": "Variant 1"},{"sku": "Variant 2"}]}}
You might have to add price if it's required.
This is an accepted solution.
Hey @MrGuvna,
Just wanted to expand on what was shared by @VivekH and a pass on a few more insights.
The "title" field in the "variants" input (ProductVariantInput.title - documentation here) is deprecated, and not a writeable field at this time. Instead, this is generated from the variant input "options" field - options must be a string for example: small, medium, red, blue, 50g, 100g etc.
Below is a mutation and input I used to create a product with multiple variants - Cheers!
EXAMPLE REQUEST:
mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
shop {
id
}
userErrors {
field
message
}
product {
id
variants(first: 5) {
edges {
node {
id
title
barcode
}
}
}
}
}
}
{
"input": {
"title": "New Product",
"variants":[
{
"barcode": "654321",
"options": "V.1"
},
{
"barcode": "765432",
"options": "V.2"
}
]
}
}
awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hello! I am trying to use GraphQL to add/update standalone products as well as multi-variant products in Shopify. For Standalone products there will be only 1 variant so the variant parameter in the mutations can be variants (first : 1) {.....} (as shown below):
mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
shop {
id
}
userErrors {
field
message
}
product {
id
variants(first: 1) {
edges {
node {
id
title
barcode
}
}
}
}
}
}
But I will come across a multi-variant product where number variant will range anywhere from 2 to may be 100. Is there any way I can dynamically map the parameter first in the variant schema of the mutation (e.g. Can I do something like variants (first: variants.length) {.....})
Thanks!