添加产品变体 - 404错误

时间:2016-07-14 14:50:02

标签: vb.net shopify

我正在开发一个VB.NET应用程序来与我们的新Shopify商店进行交互。我正在根据Oracle数据库中的数据自动添加/更新/删除产品。

基本上,应用程序为模式创建一个新的Shopify部件,然后为该模式中的每个sku创建产品变体。它通过使用HttpWebRequest类POSTing和PUTing请求来完成此操作。这个工作在昨天下午工作得非常好,现在因为某些原因它在产品变体创建/更新失败时出现了404 - Not Found错误代码。

产品添加请求JSON如下。这很有效,它在Shopify上创建了一个部分,然后我可以通过管理面板查看。这将发布到URL“https://key:password@bath-and-window-direct.myshopify.com/admin/products.json”(其中密钥和密码将替换为我们的凭据)

{
    "product": {
        "id": 0,
        "body_html": "A classic combination of embroidery and cut work form the flowing border, creating your own seaside retreat. ",
        "title": "Seabreeze Sand",
        "vendor": "SKL",
        "product_type": "",
        "published_scope": "global",
        "tags": "J71227",
        "variants": null,
        "options": null,
        "images": [{
            "id": 0,
            "product_id": 0,
            "position": 1,
            "src": "http:\/\/i320.photobucket.com\/albums\/nn353\/fkhphoto\/J71227main.jpg",
            "variant_ids": null
        }],
        "image": null
    }
}

这是我在此次通话后收到的JSON回复,我还可以看到Shopify管理面板中添加的部分:

{
    "product": {
        "id": 7874734983,
        "title": "Seabreeze Sand",
        "body_html": "A classic combination of embroidery and cut work form the flowing border, creating your own seaside retreat. ",
        "vendor": "SKL",
        "product_type": "",
        "created_at": "2016-07-14T10:43:56-04:00",
        "handle": "seabreeze-sand",
        "updated_at": "2016-07-14T10:43:56-04:00",
        "published_at": "2016-07-14T10:43:56-04:00",
        "template_suffix": null,
        "published_scope": "global",
        "tags": "J71227",
        "variants": [{
            "id": 24925005383,
            "product_id": 7874734983,
            "title": "Default Title",
            "price": "0.00",
            "sku": "",
            "position": 1,
            "grams": 0,
            "inventory_policy": "deny",
            "compare_at_price": null,
            "fulfillment_service": "manual",
            "inventory_management": null,
            "option1": "Default Title",
            "option2": null,
            "option3": null,
            "created_at": "2016-07-14T10:43:56-04:00",
            "updated_at": "2016-07-14T10:43:56-04:00",
            "taxable": true,
            "barcode": null,
            "image_id": null,
            "inventory_quantity": 1,
            "weight": 0.0,
            "weight_unit": "lb",
            "old_inventory_quantity": 1,
            "requires_shipping": true
        }],
        "options": [{
            "id": 9404426823,
            "product_id": 7874734983,
            "name": "Title",
            "position": 1,
            "values": ["Default Title"]
        }],
        "images": [{
            "id": 16242879303,
            "product_id": 7874734983,
            "position": 1,
            "created_at": "2016-07-14T10:43:56-04:00",
            "updated_at": "2016-07-14T10:43:56-04:00",
            "src": "https://cdn.shopify.com/s/files/1/1363/2407/products/J71227main.jpg?v=1468507436",
            "variant_ids": []
        }],
        "image": {
            "id": 16242879303,
            "product_id": 7874734983,
            "position": 1,
            "created_at": "2016-07-14T10:43:56-04:00",
            "updated_at": "2016-07-14T10:43:56-04:00",
            "src": "https://cdn.shopify.com/s/files/1/1363/2407/products/J71227main.jpg?v=1468507436",
            "variant_ids": []
        }
    }
}

在此之后,我正在发布以下JSON,将产品变体添加到此新创建的部分,并添加到URL“https://key:password@bath-and-window-direct.myshopify.com/admin/products/7874734983/variants.json”。这是通过HttpWebRequest类返回404 - Not Found错误的调用。

{
    "variant": {
        "id": 0,
        "product_id": 7874734983,
        "title": "Seabreeze Tier Curtain in Sand",
        "price": "11.99",
        "sku": "J7122700013V09",
        "compare_at_price": "0.00",
        "position": 0,
        "grams": 0,
        "option1": "57X13 ROD POCKET VAL",
        "option2": null,
        "option3": null,
        "taxable": true,
        "barcode": "036326422417",
        "weight": 0,
        "weight_unit": "lb",
        "inventory_quantity": 550,
        "old_inventory_quantity": 550,
        "requires_shipping": true,
        "image_id": null,
        "metafields": [{
            "id": 0,
            "key": "point1",
            "value": "57 x 13 Valance",
            "value_type": "string",
            "namespace": "J7122700013V09"
        },
        {
            "id": 0,
            "key": "point2",
            "value": "To achieve the look in the photo, use one valance and one tier pair.",
            "value_type": "string",
            "namespace": "J7122700013V09"
        },
        {
            "id": 0,
            "key": "point3",
            "value": "Feels like you are in your own beach cottage.",
            "value_type": "string",
            "namespace": "J7122700013V09"
        },
        {
            "id": 0,
            "key": "point4",
            "value": "100% Polyester.",
            "value_type": "string",
            "namespace": "J7122700013V09"
        },
        {
            "id": 0,
            "key": "point5",
            "value": " ",
            "value_type": "string",
            "namespace": "J7122700013V09"
        }]
    }
}

我做错了什么?当复制到Web浏览器中时,URL工作得非常好......我可以看到当前数据的所有JSON。但是当试图添加变体时,我得到的是404。

1 个答案:

答案 0 :(得分:1)

尝试遗漏"id": 0属性 - 来自变体和metafields。 Shopify将自动确定ID。