Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Setting available inventory using REST api from node gives an error for "inventory_item_id&

Setting available inventory using REST api from node gives an error for "inventory_item_id"!

Yagnesh
Shopify Partner
5 0 1

I'm using Shopify's official API client (@shopify/shopify-api) for node.


My system has its own inventory management system and I want it to behave as a master control thus I want to set an available amount at the inventory level via API. For that, I'm using `inventory_levels/set` endpoint on that client with post request and my JSON body looks like the following.

 

{
  inventory_item_id: 45197411975402,
  location_id: 70109757674,
  available: 177
}

 

Now when I'm trying to send a request to Shopify, I'm receiving the following error.

 

HttpResponseError: Received an error response (400 Bad Request) from Shopify:
{
  "inventory_item_id": "Required parameter missing or invalid"
}
If you report this error, please include this id: a31e7178-6bb4-4f62-8466-171f8c837f5e
    at HttpResponseError.ShopifyError [as constructor] (/xx/xx/xx/xx/node_modules/@shopify/shopify-api/dist/error.js:13:28)
    at new HttpResponseError (/xx/xx/xx/xx/node_modules/@shopify/shopify-api/dist/error.js:95:28)
    at RestClient.<anonymous> (/xx/xx/xx/xx/node_modules/@shopify/shopify-api/dist/clients/http_client/http_client.js:230:55)
    at step (/xx/xx/xx/xx/node_modules/tslib/tslib.js:144:27)
    at Object.next (/xx/xx/xx/xx/node_modules/tslib/tslib.js:125:57)
    at fulfilled (/xx/xx/xx/xx/node_modules/tslib/tslib.js:115:62)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 400,
  statusText: 'Bad Request'
}

 

I did try a few suggested solutions for similar issues (giving content type to application/json, verifying ids, etc) and it seems that none of those worked

Update - I've tested the same with Postman and I can very well confirm that it works fine in Postman. But if I change Content-Type header to something else than application/json then I receive the same error.
Now I really really believe that Node client's post method should be doing this automatically for sure but for some reason if it doesn't do that, I can see a property named extraHeaders. I've used it something like below since there is literally not a single example on how to utilize that property. The error is still the same so can anyone point out what I'm doing wrong?

 

extraHeaders: {
  'Content-Type': 'application/json',
}

 




Reply 1 (1)

Yagnesh
Shopify Partner
5 0 1

Update - I've used Axios for creating a request and it worked with setting Header to application/json. How can we achieve same using Node client?