Development discussions around Shopify APIs
To continue receiving payouts, you need to secure your account by turning on two-step authentication. If two-step authentication is not turned on your payouts will be paused. Learn more
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!
User | RANK |
---|---|
5 | |
5 | |
5 | |
4 | |
4 |
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022