【问题标题】:How to use Shopify Graphql ProductVariantsBulkInput如何使用 Shopify Graphql ProductVariantsBulkInput
【发布时间】:2021-06-18 10:59:29
【问题描述】:

我正在尝试一次批量更新多个产品变体的价格。 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.

【问题讨论】:

    标签: graphql shopify shopify-api


    【解决方案1】:

    对我来说没问题。 (有一些快速调整)

    我稍微调整了请求,因为 cursor 不存在于产品/变体对象中,不知道为什么 Shopify 没有更新他们文档中的示例。

    mutation productVariantsBulkUpdate($variants: [ProductVariantsBulkInput!]!, $productId: ID!) {
      productVariantsBulkUpdate(variants: $variants, productId: $productId) {
        product {
          id
        }
        productVariants {
          id
          price
        }
        userErrors {
          code
          field
          message
        }
      }
    }
    

    因此请尝试修复查询并删除 cursor 对象并检查您是否使用了正确的端点,因为只有在我没记错的情况下才能在不稳定版本中使用批量操作。

    请参见下图,表明我的响应正常。

    【讨论】:

    • 是的,你在所有方面都是对的!另外,只有不稳定版本的 API 支持这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 2018-12-06
    • 2020-04-22
    • 2019-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多