Re: Re:

Solved

How can I update product quantity using Shopify Flow?

Ram_A
Explorer
60 3 21

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
Explorer
60 3 21

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 22 (22)

lilyliward
Shopify Staff
18 1 8

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
18 1 8

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
Explorer
60 3 21

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
18 1 8

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
Explorer
60 3 21

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
Explorer
60 3 21

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
18 1 8

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
36 3 13

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
26 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
36 3 13

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
26 0 2

Thankyou, that is exactly what I am looking for. 

Thanks in advance.

UwDiervoeding.nl | Founder
Mussty
Excursionist
36 3 13

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
26 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
Tourist
6 0 2

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
1172 143 277

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
Tourist
6 0 2

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
1172 143 277

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
Tourist
6 0 2

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

LMiller
Shopify Partner
16 0 5

Adding my experience to this thread since it was beneficial in getting to the solution I created. What was unique about my problem was I needed to iterate through every product and use metafield variables in my POST request. In my company's situation our PIM syncs daily but can only house the stock levels in a metafield. So in my metafield with key=web_enabled_inventory that is the most accurate stock level as opposed to Shopify's that reduces/increases with orders & returns. So I need to overwrite all stock levels daily with the metafield value.

 

LMiller_1-1703721794814.png

Above is my workflow in Shopify Flow with the {store name} crossed out. You would enter your store's name there. Above in this thread does a great job already of detailing how to get Access Tokens and such. This comment here keeps it concise. The only piece missing now is below, the body of my HTTP request with some varibles you would replace bolded:

{% for metafields_item in productsForeachitem.metafields %}{% if metafields_item.key == 'web_available_inventory' %}{% for variants_item in productsForeachitem.variants %}{"location_id": [your location_id here],"inventory_item_id": {{variants_item.inventoryItem.id | split: "/" | last}},"available":{{metafields_item.value}}}{% endfor %}{% endif %}{% endfor %}

 

Hope this information helps anyone else looking to utilize Shopify Flow for inventory level automation!

Bekind24
Shopify Partner
7 0 1

Hello, I followed the steps you had here except that I removed the last 2 steps, which are the notifications. I aim to make the inventory quantity equal to 0 when it reaches 10 only. I don't know if the flow works because it says like this:

 

Screenshot 2024-07-08 122615.png

 

We are going to have a new launch of products and we want to make sure that we don't oversell, hence we make the flow.

Does this mean the flow I created doesn't work because it says "The request was unsuccessful" and the condition is true?

 

There are successful reports though, here is the sample of succeeded runs that I got:
Screenshot 2024-07-08 124158.png

Thank you so much! Big help!

paul_n
Shopify Staff
1172 143 277

If you are calling the Shopify API, use the new action, "Send Admin API Request". It's way easier and handles the API key for you.

 

That error looks like whatever API key you are using does not have the correct permissions for that mutation. You can adjust that in the Admin

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.