http request to admin inventory api via shopify flow

Solved

http request to admin inventory api via shopify flow

tony_montana
Tourist
3 1 0

Hi, I have been trying for many hours trying to send a flow request that lessens an inventory item by 1. The request is successful according to Shopify Flow however my inventory remains unaffected. This means that my api key and query format must be correct however maybe I am missing something or my syntax is off. Totally stumped on this. If anyone has any ideas, would really appreciate any help

 

I referenced the following to build a query

 

https://help.shopify.com/en/manual/shopify-flow/reference/actions/send-http-request

and

https://shopify.dev/docs/api/admin/getting-started#:~:text=%7D-,Example%20mutation,-Anchor%20link%20...

 

{"query": "mutation {inventoryAdjustQuantity(input:{inventoryLevelId: \"gid://shopify/InventoryLevel/73357459772?inventory_item_id=48137018704188\" availableDelta: -1}){inventoryLevel {available}}}"}

 

Untitledshopify.png

Accepted Solution (1)
tony_montana
Tourist
3 1 0

This is an accepted solution.

Hey Paul, thanks for getting back to me, really appreciate it. The error previously was

 

{"status":400,"response_body":"Bad Request","verb":"POST","url":"https://mystore.myshopify.com/admin/api/2023-07/graphql.json","request_body":"mutation {\n inventoryAdjustQuantity(\n input:{\n inventoryLevelId: \"gid://shopify/InventoryLevel/73357459772?inventory_item_id=48137018704188\"\n availableDelta: -1\n }\n )\n {\n inventoryLevel {\n available\n }\n }\n }"}

however there were no errors on the query I posted initially in my question, hence my confusion.

 

I actually figured out how to achieve what I wanted however. I ended up using the URL:

 

https://mystore.myshopify.com/admin/api/2023-07/inventory_levels/adjust.json

 

along with a much simpler JSON that seems to do the trick

 

{"location_id": 73357459772, "inventory_item_id": 48137018704188, "available_adjustment": -1}.

 

Perhaps you could shed some light on the difference of using graphql vs adjust.json as urls to POST to? I really didn't understand why it seemed like there were more than one way to accomplish the same thing (using the documentation I posted above). Thanks again

View solution in original post

Replies 4 (4)

paul_n
Shopify Staff
1336 151 307

Have you looked at the workflow run log to see if there is an error? If so, what does it say?

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
tony_montana
Tourist
3 1 0

This is an accepted solution.

Hey Paul, thanks for getting back to me, really appreciate it. The error previously was

 

{"status":400,"response_body":"Bad Request","verb":"POST","url":"https://mystore.myshopify.com/admin/api/2023-07/graphql.json","request_body":"mutation {\n inventoryAdjustQuantity(\n input:{\n inventoryLevelId: \"gid://shopify/InventoryLevel/73357459772?inventory_item_id=48137018704188\"\n availableDelta: -1\n }\n )\n {\n inventoryLevel {\n available\n }\n }\n }"}

however there were no errors on the query I posted initially in my question, hence my confusion.

 

I actually figured out how to achieve what I wanted however. I ended up using the URL:

 

https://mystore.myshopify.com/admin/api/2023-07/inventory_levels/adjust.json

 

along with a much simpler JSON that seems to do the trick

 

{"location_id": 73357459772, "inventory_item_id": 48137018704188, "available_adjustment": -1}.

 

Perhaps you could shed some light on the difference of using graphql vs adjust.json as urls to POST to? I really didn't understand why it seemed like there were more than one way to accomplish the same thing (using the documentation I posted above). Thanks again

paul_n
Shopify Staff
1336 151 307

REST is easier in that action for sure. Shopify supports 2 Admin APIs (REST vs GraphQL). The latter is generally preferred because it allows traversing a graph better than REST and allows you to only request the data you need. 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
tony_montana
Tourist
3 1 0

Thanks Paul for your help