如何使用 Shopify Graphql ProductVariantsBulkInput
How to use Shopify Graphql ProductVariantsBulkInput
我正在尝试一次批量更新多个产品变体的价格。 I'm just copying the "interactive" example from Shopify's page
我所做的只是复制并粘贴代码并输入我自己的 ID。当然也行不通。
看起来像这样:
mutation productVariantsBulkUpdate($variants: [ProductVariantsBulkInput!]!, $productId: ID!) {
productVariantsBulkUpdate(variants: $variants, productId: $productId) {
product {
cursor
}
productVariants {
cursor
}
userErrors {
code
field
message
}
}
}
使用这样的变量:
{
"variants": [
{
id: "gid://shopify/ProductVariant/39369514385591",
price: "50.00"
}
],
"productId": "gid://shopify/Product/6591908577463"
}
我收到此错误:
Variables are invalid JSON: Unexpected token i in JSON at position 30.
对我来说没问题。 (进行一些快速调整)
我稍微调整了请求,因为 cursor
不存在于 product/variant 对象中,不知道为什么 Shopify 没有更新他们文档中的示例。
mutation productVariantsBulkUpdate($variants: [ProductVariantsBulkInput!]!, $productId: ID!) {
productVariantsBulkUpdate(variants: $variants, productId: $productId) {
product {
id
}
productVariants {
id
price
}
userErrors {
code
field
message
}
}
}
因此,请尝试修复查询并删除 cursor
对象,并检查您是否使用了正确的端点,因为只有在我没有弄错的情况下批量操作才可用于不稳定版本。
参见下图,显示响应对我来说还可以。
我正在尝试一次批量更新多个产品变体的价格。 I'm just copying the "interactive" example from Shopify's page
我所做的只是复制并粘贴代码并输入我自己的 ID。当然也行不通。
看起来像这样:
mutation productVariantsBulkUpdate($variants: [ProductVariantsBulkInput!]!, $productId: ID!) {
productVariantsBulkUpdate(variants: $variants, productId: $productId) {
product {
cursor
}
productVariants {
cursor
}
userErrors {
code
field
message
}
}
}
使用这样的变量:
{
"variants": [
{
id: "gid://shopify/ProductVariant/39369514385591",
price: "50.00"
}
],
"productId": "gid://shopify/Product/6591908577463"
}
我收到此错误:
Variables are invalid JSON: Unexpected token i in JSON at position 30.
对我来说没问题。 (进行一些快速调整)
我稍微调整了请求,因为 cursor
不存在于 product/variant 对象中,不知道为什么 Shopify 没有更新他们文档中的示例。
mutation productVariantsBulkUpdate($variants: [ProductVariantsBulkInput!]!, $productId: ID!) {
productVariantsBulkUpdate(variants: $variants, productId: $productId) {
product {
id
}
productVariants {
id
price
}
userErrors {
code
field
message
}
}
}
因此,请尝试修复查询并删除 cursor
对象,并检查您是否使用了正确的端点,因为只有在我没有弄错的情况下批量操作才可用于不稳定版本。
参见下图,显示响应对我来说还可以。