Shopify GraphQL:如何向产品添加多个变体?
Shopify GraphQL: How to add multiple variants to a product?
我正在关注 GraphQL documentation for `productCreate,但我不知道如何在创建产品时添加多个变体。
我正在使用以下突变:
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
}
}
}
}
我在网上搜索过,试图找出在 Shopify 上创建产品时如何添加多个变体,但我想不出来。
可以这样做吗?
我错误地定义了变体。如果没有 options
键(这很奇怪,考虑到它只需要一个字符串,它是复数?)它不会工作。
{
"input": {
"title": "Testing Products",
"handle": "test-product-2",
"variants": [
{
"title": "Size Small",
"options": "Small"
},
{
"title": "Size Medium",
"options": "Medium"
},
{
"title": "Size Large",
"options": "Large"
}
]
}
}
我正在关注 GraphQL documentation for `productCreate,但我不知道如何在创建产品时添加多个变体。
我正在使用以下突变:
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
}
}
}
}
我在网上搜索过,试图找出在 Shopify 上创建产品时如何添加多个变体,但我想不出来。
可以这样做吗?
我错误地定义了变体。如果没有 options
键(这很奇怪,考虑到它只需要一个字符串,它是复数?)它不会工作。
{
"input": {
"title": "Testing Products",
"handle": "test-product-2",
"variants": [
{
"title": "Size Small",
"options": "Small"
},
{
"title": "Size Medium",
"options": "Medium"
},
{
"title": "Size Large",
"options": "Large"
}
]
}
}