【发布时间】:2013-03-07 16:53:06
【问题描述】:
当我更新具有多个变体的产品时,我收到一个错误 回复:
{"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,它可以工作。这确实意味着删除一个 变体并重新创建它,我认为这是不可接受的 插件的行为,特别是因为我没有所有数据 关于存储的变体,因此无法推广到 生产。
为此,我提出了以下 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 和 recreated 已更改(我可以通过获取请求来判断):
{"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 中的错误吗?
【问题讨论】:
标签: shopify