Shopify API重复PUT具有不同的结果(选项不是唯一的)

时间:2013-03-07 16:53:06

标签: shopify

当我更新具有多个变体的产品时,出现错误 响应:

{"errors":{"base":["Options are not unique"]}}

或有时:

{"errors":{"variants":["is invalid"], "base":["Options are not unique"]}}

我正在向类似的东西发出PUT请求 /admin/products/122821632.json,数据如:

{"product":{"id":"122821632",
           "body_html":"test",
           "vendor":"Acme",
           "title":"Monkey T-Shirt",
           "variants":[{"option1":"LARGE",
                        "sku":"test-sku-2",
                        "product_id":"122821632",
                        "id":"282988194",
                        "price":"21.99",
                        "grams":"200"},
                       {"option1":"TINY",
                        "sku":"test-sku-1",
                        "product_id":"122821632",
                        "id":"282990692",
                        "price":"21.99",
                        "grams":"200"}],
           "options":[{"position":1,
                       "name":"Size",
                        "product_id":"122821632"}]}}

但是我注意到,如果我放一个变种,然后放 多变量数据JSON,它的工作原理。这意味着删除a 变种并重新创造它,我认为这是不可接受的 插件的行为,尤其是因为我没有所有数据 关于存储的变种,因此无法推出 生产

为此我做了这些PUT请求:

{"product":{"id":"122821632",
           "body_html":"test",
           "vendor":"Acme",
           "title":"Monkey T-Shirt",
           "variants":[{"option1":"LARGE",
                        "sku":"test-sku-2",
                        "product_id":"122821632",
                        "id":"282988194",
                        "price":"21.99",
                        "grams":"200"}],
           "options":[{"position":1,
                       "name":"Size",
                       "product_id":"122821632"}]}}

返回200.其次是:

{"product":{"id":"122821632",
           "body_html":"test",
           "vendor":"Acme",
           "title":"Monkey T-Shirt",
           "variants":[{"option1":"LARGE",
                        "sku":"test-sku-2",
                        "product_id":"122821632",
                        "id":"282988194",
                        "price":"21.99",
                        "grams":"200"},
                       {"option1":"TINY",
                        "sku":"test-sku-1",
                        "product_id":"122821632",
                        "id":"282990692",
                        "price":"21.99",
                        "grams":"200"}],
           "options":[{"position":1,
                       "name":"Size",
                       "product_id":"122821632"}]}}

返回200.其次是:

{"product":{"id":"122821632",
           "body_html":"test",
           "vendor":"Acme",
           "title":"Monkey T-Shirt",
           "variants":[{"option1":"LARGE",
                        "sku":"test-sku-2",
                        "product_id":"122821632",
                        "id":"282988194",
                        "price":"21.99",
                        "grams":"200"},
                       {"option1":"TINY",
                        "sku":"test-sku-1",
                        "product_id":"122821632",
                        "id":"282990692",
                        "price":"21.99",
                        "grams":"200"}],
           "options":[{"position":1,
                       "name":"Size",
                       "product_id":"122821632"}]}}

这给了我错误。我删除的变体的ID也是 重新创建已更改(我可以通过get请求告诉):

{"product":{"body_html":"test",
            "handle":"69",
            "images":[],
            "template_suffix":null,
            "product_type":"Shirts",
            "updated_at":"2013-03-07T11:36:51-05:00",
            "variants":[{"position":1,
                         "option1":"LARGE",
                         "option2":null,
                         "option3":null,
                         "updated_at":"2013-03-07T07:30:15-05:00",
                         "inventory_quantity":1,
                         "title":"LARGE",
                         "product_id":122821632,
                         "created_at":"2013-03-06T11:03:36-05:00",
                         "compare_at_price":"24.99",
                         "fulfillment_service":"manual",
                         "inventory_management":"",
                         "sku":"test-sku-2",
                         "taxable":true,
                         "requires_shipping":true,
                         "price":"21.99",
                         "inventory_policy":"deny",
                         "id":282988194,
                         "grams":200},
                        {"position":2,
                         "option1":"TINY",
                         "option2":null,
                         "option3":null,
                         "updated_at":"2013-03-07T11:36:51-05:00",
                         "inventory_quantity":1,
                         "title":"TINY",
                         "product_id":122821632,
                         "created_at":"2013-03-07T11:36:51-05:00",
                         "compare_at_price":null,
                         "fulfillment_service":"manual",
                         "inventory_management":null,
                         "sku":"test-sku-1",
                         "taxable":true,
                         "requires_shipping":true,
                         "price":"21.99",
                         "inventory_policy":"deny",
                         "id":283397624,
                         "grams":200}],
            "title":"Monkey T-Shirt",
            "created_at":"2013-02-22T05:35:02-05:00",
            "options":[{"id":147204272,
                        "name":"Size",
                        "position":1,
                        "product_id":122821632}],
            "vendor":"Acme",
            "id":122821632,
            "published_at":"2013-02-22T05:35:02-05:00",
            "tags":"mens t-shirt example"}}

我的印象是第二个PUT请求相同的数据 到相同的URL应该没有变化。

我做错了什么?这是Shopify API中的错误吗?

2 个答案:

答案 0 :(得分:0)

我的朋友,当我这样做时,我曾经通知选项ID ...所以选项部分会保持这样:

"options":[{"id":147204272,"position":1,"name":"Size","product_id":"122821632"}]}}

选项类似于json的变体,它们也有id。图像也会发生同样的情况。

让我知道它是否有帮助。

答案 1 :(得分:0)

我和你昨天有同样的问题。看起来您不能使用PUT /admin/products/122821632.json来修改变体。

使用变体创建产品后,您必须使用http://docs.shopify.com/api/product_variant#update更新各个变体,否则如果在产品PUT中包含变体数据,则会出现该错误。

如果您想在设置变体后更新它,则必须错过产品PUT中的所有变体信息。