2016-07-14 70 views
0

我正在開發一個VB.NET應用程序來與我們的新Shopify商店進行交互。我正在根據Oracle數據庫中的數據自動化產品添加/更新/刪除。添加產品變種 - 404錯誤

基本上,應用程序會爲某個模式創建一個新的Shopify部件,然後爲該模式中的每個sku創建產品變體。它通過使用HttpWebRequest類的POSTing和PUTing請求完成此操作。這在昨天下午工作良好,現在由於某種原因,它在產品變體創建/更新上沒有404 - Not Found錯誤代碼。

產品添加請求JSON如下。這完美地工作,它創建Shopify上的部分,然後我可以通過管理面板看到。這是張貼到URL「https://key:[email protected]/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:[email protected]/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個。

回答

1

嘗試省略"id": 0屬性 - 無論是從變體還是從元域。 Shopify將自動確定ID。

+0

這對我有效,但我只是因爲某些原因不得不從metafields中刪除''id::0'屬性。我一直在產品,產品變體,產品圖像和訂單上發送同樣的東西,但是將其留在metafield上會引發404 Not Found錯誤,這看起來不合適。謝謝一堆! – RianBattle

+0

'id'僅在更新內容時使用。 'variants/ .json'或'metafields/ .json' – HymnZ