【问题标题】:Add Product Variant - 404 Error添加产品变体 - 404 错误
【发布时间】:2016-07-14 14:50:02
【问题描述】:

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

基本上,该应用程序会为模式创建一个新的 Shopify 部件,然后为该模式中的每个 sku 创建产品变体。它通过使用 HttpWebRequest 类 POST 和 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 以将产品变体添加到这个新创建的部件,网址为“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"
        }]
    }
}

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

【问题讨论】:

    标签: vb.net shopify


    【解决方案1】:

    尝试忽略变体和元字段中的"id": 0 属性。 Shopify 将自动确定 ID。

    【讨论】:

    • 这对我有用,尽管出于某种原因我只需要从元字段中删除 "id": 0 属性。我一直在产品、产品变体、产品图像和订单上发送相同的内容,没有问题,但将其留在元字段上会引发 404 Not Found 错误,这似乎不合适。非常感谢!
    • id 仅在您更新某些内容时使用。 variants/<id>.jsonmetafields/<id>.json
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 2019-07-29
    • 2015-03-04
    相关资源
    最近更新 更多