Development discussions around Shopify APIs
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
User | RANK |
---|---|
8 | |
7 | |
4 | |
3 | |
3 |
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...
ByYour online store speed can enhance your store’s discoverability, boost conversion rates a...
ByShopping is at our fingertips with mobile devices. Is your theme optimized to be user-frie...
By