Inventory_level/Set.Json Not Working Error(400) Bad Request | 2023-04 REST API | Custom App

Inventory_level/Set.Json Not Working Error(400) Bad Request | 2023-04 REST API | Custom App

immpek
Tourist
4 0 1

Hello,

 

Am trying to perform an Admin API POST using CURL to set inventory level via a Custom App, per https://shopify.dev/docs/api/admin-rest/2023-04/resources/inventorylevel#post-inventory-levels-set instruction.

 

The item_inventory_id and location_id have been verified correctly, since I'm able to perform "GET"  methods for inventory_level, but for POST am getting 400 Bad Request Error.  I'm at a loss as to why.

 

I've reviewed past Shopify Developer postings regarding similar errors, but they haven't helped.  As far I'm aware CURL doesn't send any cookies.

 

 

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
 
Swapping  position "inventory_item_id" to be listed first in JSON payload didn't help
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
 
Changing the content type to "application/x-ndjson" alters the response a bit, got a bit more detail in the returned JSON payload, but doesn't really make sense...
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
 
Swapping  position "inventory_item_id"  with ndjson to be listed first in JSON payload also didn't help
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
 
 
Successful GETs and verification that inventory_item_id & location_id are accurate:
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"}]}
 
In addition, I've also confirmed that the item is being tracked
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"}]}

 

I think I also have the appropriate Custom App permissions to write to 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

 

Any help would be greatly appreciated, and thanks in advance.

 

Regards,

Immanuel

 

Replies 6 (6)

immpek
Tourist
4 0 1

I'm a newbie on this forum.

 

But just wondering if it would help if I post the X-Request-ID: d2fa99f8-7ee1-49cf-9dea-7dce8807fee6 here, I've seen some posts where someone had been helped after being asked for the X-Request-ID.  Perhaps a representative from Shopify might be able to provide more insight to the error rather than simply returning "Bad Request" by looking up said X-Request-ID.

 

Regards,

Immanuel

anaconx
Visitor
2 0 1

Hello @immpek, Have you found any solution for this issue? I face the same problem while updating the inventory level via REST APIs. If you have any solution I really would like to get that solution.

Looking forward to getting a reply from you.

Thank you,

Hardik Zinzuvadiya

 

immpek
Tourist
4 0 1

Hello @anaconx,

 

I wasn't able to get it to work using CURL, but I did get it to work using POSTMAN instead.  So, unfortunately, I still don't know what exactly was wrong with the CURL command.

 

Furthermore, I ended up using a combination of REST API and GraphQL calls for my solution.

 

  • First, I would grab the entire set of inventory_levels for all products at a location using REST API since GraphQL doesn't seem to offer anything like it (at least, I wasn't able to find it).  GET /admin/api/2023-04/locations/85585123456/inventory_levels.json?limit=250.
  • Compare Shopify Qty Available against our back-end  Qty Available
  • Create a Qty Adjustment delta list
  • Then call a GraphQL for mutation InventoryBulkAdjustQuantitiesAtLocationMutation  (HTTP POST) with the inventory_item_id & available based on the abovementioned delta list as the GraphQL's "variables".  The GraphQL call was done so that I can make a bunch of adjustments with a single API call, and also to make sure that I don't hit up against Shopify's API Rate limit as opposed to calling repeated REST API /admin/api/2023-04/inventory_levels/set.json which can only do one product at a time.

Hope that helps.

 

Regards,

Immanuel

 

AmberLaflamme
Visitor
2 0 0

It seems like you're encountering a 400 Bad Request error when performing the Admin API POST with CURL. Have you double-checked your parameters?

AmberLaflamme
Visitor
2 0 0

Hi Immanuel, However, there are a few things you can double-check to ensure that the request is formatted correctly Make sure you're using the correct API version.

immpek
Tourist
4 0 1

Hello @AmberLaflamme,

 

Yes, I checked the parameters, I literally copied & pasted the curl command per Shopify's dev doc example:  https://shopify.dev/docs/api/admin-rest/2023-04/resources/inventorylevel#post-inventory-levels-set

 

Since I was able to get it to work using POSTMAN, I didn't pursue the CURL issue any further.

 

-Immanuel