New Shopify Certification now available: Liquid Storefronts for Theme Developers

Shopify Flow Inventory Update

Solved
Ram_A
Excursionist
42 3 10

Hi,

 

Is there any way to update the quantity of specific products using Shopify Flow? not looking to use any 3rd part apps.

 

e.g. Trigger happened >>  set the quantity for a specific product to 100.

I don't want to hide/unhide the product, I just want to auto-update the inventory.

 

is it possible by using flow,  I searched on all templates and couldn't find one.

Thanks

Accepted Solution (1)
Ram_A
Excursionist
42 3 10

This is an accepted solution.

Thanks, Lily for your help, although it wasn't exactly what I was looking for, it did lead me in the right direction and I was able to find a solution that worked for me. I appreciate your assistance.

In case anyone looking for the same thing here is what worked for me: 

use Post instead of Put, and use this URL to set the inventory level:
https://your-development-store.myshopify.com/admin/api/2023-01/inventory_levels/set.json

Body:
{"location_id": 213334567,"inventory_item_id": 12345467789,"available":33}



Screenshot 2023-01-29 at 16.57.32 Medium.jpeg

View solution in original post

Replies 19 (19)
lilyliward
Shopify Staff
Shopify Staff
14 0 6

Hi, 

 

We do not have a Flow action to do that yet. However, if you have some technical skills, you could do that now by calling the Shopify admin API to update the product inventory. We don't have any plans yet to add this action short-term, but we've made a note that you are looking for it. 

 

Hope this helps. 

 

Lily

To learn more visit the Shopify Help Center or the Community Blog.

lilyliward
Shopify Staff
Shopify Staff
14 0 6

BTW, in order to help prioritization of this request, I suggest that you add a request at the merchant frustration

To learn more visit the Shopify Help Center or the Community Blog.

Ram_A
Excursionist
42 3 10

Thanks, Lily,

Do you mean using shopify admin API  + Shopify Folw? or this could be done usnig  Shopify Admin API alone?  

would appreciate it if you could share some more example in what I should connect Shopify Admin API to?

Thanks

lilyliward
Shopify Staff
Shopify Staff
14 0 6

Yes, I do mean to use Shopify admin API + Shopify Flow.

 

BTW, the previous link I gave you is GraphQL API, which I don't think can easily used by you. Instead, you should use the REST API . The API has details on the header you need as well in the example:

 

```

curl -d '{"variant":{"id":808950810,"metafields":[{"key":"new","value":"newvalue","type":"single_line_text_field","namespace":"global"}]}}' \
-X PUT "https://your-development-store.myshopify.com/admin/api/2022-10/variants/808950810.json" \
-H "X-Shopify-Access-Token: {access_token}" \
-H "Content-Type: application/json"

```

 

In order to get an `access_token`, you could follow this instruction

 

You could use the `Send HTTP Request` action in Flow. So, the flow would look something like this:

 

Screenshot 2023-01-27 at 4.14.17 PM.png

To learn more visit the Shopify Help Center or the Community Blog.

Ram_A
Excursionist
42 3 10

Thank you, Lily, for your helpful insight and support. I am still encountering below error, even after changing "newvalue" to "100" as the desired quantity setting and attempting to leave "newvalue" as is, still get the same error.


Screenshot 2023-01-28 at 17.08.10 Medium.jpeg
Screenshot 2023-01-28 at 17.14.50 Large.jpeg

Ram_A
Excursionist
42 3 10

This is an accepted solution.

Thanks, Lily for your help, although it wasn't exactly what I was looking for, it did lead me in the right direction and I was able to find a solution that worked for me. I appreciate your assistance.

In case anyone looking for the same thing here is what worked for me: 

use Post instead of Put, and use this URL to set the inventory level:
https://your-development-store.myshopify.com/admin/api/2023-01/inventory_levels/set.json

Body:
{"location_id": 213334567,"inventory_item_id": 12345467789,"available":33}



Screenshot 2023-01-29 at 16.57.32 Medium.jpeg

lilyliward
Shopify Staff
Shopify Staff
14 0 6

Nice! Though I was no expert on the admin API, I was happy to have helped. 🙂 

To learn more visit the Shopify Help Center or the Community Blog.

Mussty
Excursionist
30 3 6

Thanks buddy, this helped so much!! Just want to add some additional info for other noobs like me! 🙂

 

To get API Access Token I followed this: https://mixedanalytics.com/knowledge-base/get-your-shopify-access-token/

 

Location Id: Go to Shopify Settings and select the location, you can find the location ID in the URL. 

 

Inventory Item ID: I used {{productVariant.inventoryItem.legacyResourceId}}

 

Available: Input number for desired inventory amount to insert. 

 

For me it looked something like this (I wanted to set quantity to 0 based on my conditions):

{"location_id": 213334567,"inventory_item_id": {{productVariant.inventoryItem.legacyResourceId}},"available": 0}

 

Bonus Tip: I setup an internal email action at the end to also notify me every time the flow automation set a product inventory to 0. 

stanlegebeke
Excursionist
20 0 2

Hello Mussty,

For example can you set a rule when the stocklevel is 2 you let shopify flow edit it to 0?
I would like that or do you not have something like this?

Kind regards
Stan Legebeke

UwDiervoeding.nl | Founder
Mussty
Excursionist
30 3 6

Hi Stan, I have done exactly this, for me when stock level reaches 3 or less I overide stock level to 0 with shopify flow using the method above. I cant open flow on my phone with full view, I will reply tomorrow with a screenshot from my laptop on how how I did it. 

stanlegebeke
Excursionist
20 0 2

Thankyou, that is exactly what I am looking for. 

Thanks in advance.

UwDiervoeding.nl | Founder
Mussty
Excursionist
30 3 6

Hi Stan, no worries at all!

 

Here is how my flow automation is set up: I will probably remove the email at the end as it gets annoying. I set it up just to see if it was working as intended.

 

Mussty_0-1681662537322.png

Send HTTP Request setup:

 

Mussty_1-1681662747286.png

 

Email Setup: 

 

Mussty_2-1681662899718.png

 

If you follow the rest it should be easy to set up. 

 

stanlegebeke
Excursionist
20 0 2

Thanks a lot, I will implement it and hope it reduces a lot of issues when product stock is low.

UwDiervoeding.nl | Founder
BBPT
Visitor
3 0 0

Hello Mussty,

 

I have been working on this for a few days, but can't seem to get it to work. I want to create a flow that adjusts the inventory of an item once monthly, when I run the flow it get 

{"errors":"Not Found"}

Same thing when I follow the link itself. Not sure what is wrong, I believe I followed everything mentioned in the thread. Were there any other steps you took?

 

Bit of a noob, appreciate any help!

paul_n
Shopify Staff
Shopify Staff
614 98 158

You are getting that on the Send HTTP Request? I think it would help to see your configuration but my first guess is that you are using the wrong ID to set inventory.

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.
BBPT
Visitor
3 0 0

Hi Paul, yes that's right. Attaching the configuration and exact error below.

BBPT_0-1692221274401.png



{"status":404,"response_body":"{\"errors\":\"Not Found\"}","verb":"POST","url":"https://your-store.myshopify.com/admin/api/2023-01/inventory_levels/set.json","request_body":"{\"location_id\": xyz,\"inventory_item_id\": xyz,\"available\":5}\n\n"}


Thanks in Advance!

paul_n
Shopify Staff
Shopify Staff
614 98 158

Are you sure the ID's match? Probably doesn't matter but remove any whitespace after the string, since I see 2 newlines. Is neither of those work, try it with postman or some API client to get it working. 

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.
BBPT
Visitor
3 0 0

Hi Paul, when you are referring to ID do you mean Store ID, inventory ID, or Location ID? I have a feeling that the URL is the problem as its giving a 404 and I was actually able to accidentally access the login page of other stores with the same API. I have checked the Store ID several times to ensure it is accurate.

vpf
Visitor
1 0 0

Hi!

 

Really appreciate the help I got here!


BBPT I was stuck on with the same 404 error and you might have the same issue.
Note that the "inventory_item_id" is not the same value as the variant ID you can pick up on the product/variant page link.
I used Matrixify to retrieve the variables I needed but you can also get via API.

You can use /adjust to add or subtract a quantity instead of setting a value.

Hope this helps! 

 

api.jpg