用于 Inventory_level/Set.Json 的 Shopify 自定义应用程序管理 REST API 无法正常工作并收到错误 (400) 错误请求

问题描述 投票:0回答:1

我尝试使用 CURL 执行管理 API POST,以通过自定义应用程序设置库存水平,按照 https://shopify.dev/docs/api/admin-rest/2023-04/resources/inventorylevel#post-库存水平设置指令。

item_inventory_id
location_id
已被验证是正确的,因为我已经能够成功地对
inventory_level
执行GET方法,但对于POST我得到
400 Bad Request Error
。我不知道为什么。

HTTP/1.1 400 Bad Request | No JSON Error message returned

curl -X POST -v -u myAPIkey:mySecretKey -H "Content-Type: application/json" -H "X-Shopify-Access-Token: myAccessToken"  -d '{"location_id":85585101078,"inventory_item_id":47065562448150,"available":46}' https://test123.myshopify.com/admin/api/2023-04/inventory_levels/set.json

交换位置

inventory_item_id
在 JSON 负载中首先列出并没有帮助:

curl -X POST -v -u myAPIkey:mySecretKey -H "Content-Type: application/json" -H "X-Shopify-Access-Token: myAccessToken"  -d '{"inventory_item_id":47065562448150,"location_id":85585101078,"available":46}' https://test123.myshopify.com/admin/api/2023-04/inventory_levels/set.json

将内容类型更改为

application/x-ndjson
会稍微改变响应,在返回的 JSON 负载中获得更多详细信息,但实际上没有意义...

HTTP/1.1 400 Bad Request | {"errors":{"inventory_item_id":"Required parameter missing or invalid"}}


curl -X POST -v -u myAPIkey:mySecretKey -H "Content-Type: application/x-ndjson; charset=utf-8" -H "X-Shopify-Access-Token: myAccessToken"  -d '{"location_id":85585101078,"inventory_item_id":47065562448150,"available":46}' https://test123.myshopify.com/admin/api/2023-04/inventory_levels/set.json

inventory_item_id
ndjson
交换位置以在 JSON 负载中首先列出也没有帮助:

curl -X POST -v -u myAPIkey:mySecretKey -H "Content-Type: application/x-ndjson; charset=utf-8" -H "X-Shopify-Access-Token: myAccessToken"  -d '{"inventory_item_id":47065562448150,"location_id":85585101078,"available":46}' https://test123.myshopify.com/admin/api/2023-04/inventory_levels/set.json

以下是通过成功的 GET 方法证明

inventory_item_id
location_id
是准确的证据:

curl -X GET -v -u myAPIkey:mySecretKey -H "Content-Type: application/json" -H "X-Shopify-Access-Token: myAccessToken" https://test123.myshopify.com/admin/api/2023-04/inventory_levels.json?inventory_item_ids=47065562448...
{"inventory_levels":[{"inventory_item_id":47065562448150,"location_id":85585101078,"available":999999,"updated_at":"2023-06-22T15:41:35-05:00","admin_graphql_api_id":"gid:\/\/shopify\/InventoryLevel\/122010075414?inventory_item_id=47065562448150"}]}

此外,我还确认了该物品正在被追踪

curl -X GET -v -u myAPIkey:mySecretKey -H "Content-Type: application/json" -H "X-Shopify-Access-Token: myAccessToken" https://test123.myshopify.com/admin/api/2023-04/inventory_items.json?ids=47065562448150
{"inventory_items":[{"id":47065562448150,"sku":"735X453","created_at":"2023-06-16T09:15:53-05:00","updated_at":"2023-06-22T15:41:30-05:00","requires_shipping":true,"cost":null,"country_code_of_origin":null,"province_code_of_origin":null,"harmonized_system_code":null,"tracked":true,"country_harmonized_system_codes":[],"admin_graphql_api_id":"gid:\/\/shopify\/InventoryItem\/47065562448150"}]}

我相信我还为自定义应用程序配置了适当的权限来写入

inventory_levels

read_fulfillments, **write_inventory, read_inventory**, write_merchant_managed_fulfillment_orders, read_merchant_managed_fulfillment_orders, write_order_edits, read_order_edits, write_orders, read_orders, write_payment_customizations, read_payment_customizations, write_payment_terms, read_payment_terms, write_price_rules, read_price_rules, write_product_feeds, read_product_feeds, write_product_listings, read_product_listings, write_products, read_products, write_reports, read_reports, write_returns, read_returns, write_third_party_fulfillment_orders, read_third_party_fulfillment_orders, write_fulfillment_constraint_rules, read_fulfillment_constraint_rules

尝试在

order.tags
上执行更新时,我也遇到了同样的问题。

成功

curl -X GET -v -u myAPIkey:myAPIsecret -H "Content-Type: application/json" -H "X-Shopify-Access-Token: myAccessToken" https://test123.myshopify.com/admin/api/2023-04/orders/5384975778070.json?

但是“PUT”API 调用失败:错误请求

curl -X PUT -v -u myAPIkey:myAPIsecret -H "Content-Type: application/json" -H "X-Shopify-Access-Token: myAccessToken" -d '{"order":{"id":5384975778070,"tags":"exported"}}' https://test123.myshopify.com/admin/api/2023-04/orders/5384975778070.json

到目前为止,Shopify 支持声称这超出了他们的支持范围,不幸的是,Shopify 社区没有提供任何帮助。

预计会收到 200 响应和 JSON 有效负载,确认更新成功。它可能看起来像这样。

'{"inventory_item_id":47065562448150,"location_id":,"available":46}' https://test123.myshopify.com/admin/api/2023-04/inventory_levels/set.json

HTTP/1.1 200 OK
{
  "inventory_level": {
    "inventory_item_id": 47065562448150,
    "location_id": 85585101078,
    "available": 46,
    "updated_at": "2023-06-14T15:00:18-04:00",
    "admin_graphql_api_id": "gid://shopify/InventoryLevel/655441491?inventory_item_id=47065562448150"
  }
}
shopify shopify-app shopify-api
1个回答
0
投票

您解决这个问题了吗?我有同样的问题。进行了类似的故障排除,但无法弄清楚。我什至已经确认该应用程序具有所需的权限。

© www.soinside.com 2019 - 2024. All rights reserved.