Update Product handle after create

Update Product handle after create

daviscomp
Visitor
1 0 0

We are not using the vendor name in our product titles so I wanted to have the handle get automatically set after each item is created to be equal to the vendor concatenated with the product title ( separated by a dash ) but for some reason it doesn't appear to be working.  I thought this would be pretty easy but I'm stumped.  Attached is a picture of the workflow along with the action

 

For example .. if we have Vendor "ABC" and the product title is "Beach Ball", the desired outcome would be the handle for the product would be "ABC-Beach-Ball"screenshotflow.jpg

 

Thank you for your time!

Replies 17 (17)

paul_n
Shopify Staff
1817 199 432

you are trying to update a metafield here and not a the handle field on a product. There is a new action called Send Admin API request, which would allow you to call "productUpdate" and change the handle. 

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.
gary07
Excursionist
65 0 12

Hi Paul 

 

Any idea why the below is not working handle is not updating

 

gary07_1-1721047480579.png

 

 

 

 

paul_n
Shopify Staff
1817 199 432

That is creating a redirect and will not change the handle. As a said easier, use the Send Admin API request action to call productUpdate to change the handle. You would put something like this in the JSON:

{
  "input": {
    "handle": "your new handle",
    "id": "{{ product.id }}",
}
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.
gary07
Excursionist
65 0 12

Thanks for quick reply Paul

 

I am using the below and getting the error 

Mutation input evaluated to invalid JSON. Please ensure the input forms valid JSON after Liquid code is run.

 

{
"input": { "handle": {{product.title | downcase | replace: "/", " " | replace: " ", "-"}}, "id": "{{ product.id }}", }

paul_n
Shopify Staff
1817 199 432

Typically to troubleshoot I would use a "Log output" action (before this action) to show exactly what that Liquid renders to. And if necessary copy it to a JSON validator to see what is wrong.

 

Two obvious problems: you don't have quotes around the liquid for the handle, and you have a trailing comma after the product.id part, neither of which is valid JSON.

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.
gary07
Excursionist
65 0 12

Hi When I log the output it shows the correct 

[{"input":  { "handle": "hotpoint-hbnf55182wuk-183cm-high-50-50-frost-free-fridge-freezer-white-e-rated", "id": "gid://shopify/Product/8501690564831"}]

 

I have tried the urlRedirectUpdate &  urlRedirectCreate Mutation but on the backend  and frontend still show old handle 

 

gary07_1-1721055871779.png

On URL redirect showing correctly as well

 

gary07_2-1721055945758.png

 

I can not see error

 

 

233

 

paul_n
Shopify Staff
1817 199 432

Why are you trying to set redirects? Those don't change the handle. They just map from on URL to another.

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.
gary07
Excursionist
65 0 12

When our EPOS push the product it set as draft product and shopify added the handle automatic 

 

For example, our epos sends the product to Shopify and the title is lg machine copy so Shopify default update the handle to lg-machine-copy so when I update the product title to lg washing machine 8kg 1200 spin white I want to update the handle automatically to lg-washing-machine-8kg-1200-spin-white

 

This is my new title

gary07_0-1721057480764.png

 

This is what our epos added 

 

gary07_2-1721058076466.png

 

 

 

paul_n
Shopify Staff
1817 199 432

OK, but you are setting a redirect which is not a handle. 

 

You need to use productUpdate as the API mutation with what I showed above. 

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.
gary07
Excursionist
65 0 12

Thanks productUpdate work 

 

Do you also know if I want to fetch and update updated products what will be the solution as get products gives only 100 products

paul_n
Shopify Staff
1817 199 432

You can run a scheduled workflow as frequently as every 10 min, so you could process 600 updates every hour. You can also narrow your query to get a subset of products that you actually need to update. Be careful though updating products that were just updated, as those will then show up in your query again. If you do that, you need to mark the products that have processed (eg., add a "processed" tag and query only products that don't have that tag). 

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.
gary07
Excursionist
65 0 12

Hi Paul

 

I tried below but did not get the data I wanted

 

I have 6000 products with 4000 active products and I want to add tag nopreorder 

 

on active product has preorder tag and Continue selling when out of stock not ticked

 

 

gary07_0-1721147583311.png

gary07_1-1721147698250.png

 

 

gary07_2-1721147717371.pnggary07_3-1721147750917.png

gary07_4-1721147776876.png

 

paul_n
Shopify Staff
1817 199 432

What is not working? Like what data was returned and why wasn't it correct?

 

At the very least, your query should include "tag_not:preorder" so that after the tag is added, it's not returned in the query. 

 

Also, your condition is checking is any of the returned products have a "preorder" tag and only tries to add a tag if that is true. Pretty sure you want to check each individual product AND you want to check if it doesn't have the tag. But if you move that to the query, it's a better solution. 

 

Your other condition is also checking the wrong thing. You are again checking is any product matches. You need to choose the "For each product item" variable, which is the product in that instance of the loop. 

 

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.
gary07
Excursionist
65 0 12

Hi Paul 

 

I don't what's incorrect if you able to help

 

I just want to add a "no-preorder" tag to the below condition

 

Product Status Active AND Inventory policy = DENY AND Tags:preorder

 

As per your suggestion, I have chosen "For each product item" but the product is not add tag

 

 

paul_n
Shopify Staff
1817 199 432

I think you should contact support and provide them with this thread and a link to your workflow, it's hard to map your words to a workflow that we can't see here.

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.
gary07
Excursionist
65 0 12

Hi Paul

 

I have reached the support and they give baseless reply

it seems like the issue you're encountering with the Shopify Flow not adding tags might be due to another app or admin user overwriting the tag after it has been set by Flow. This is a common issue when multiple apps use the same event triggers. A potential solution is to insert a 'Wait' step in your Flow to delay the tag addition, giving other processes time to complete before the tag is added.

 

I have attached a photo with steps I have taken on the flow see if you can help me

 

gary07_0-1721302611700.png

 

gary07_1-1721302630218.png

 

 

gary07_2-1721302642863.png

 

 

gary07_3-1721302655181.png

 

 

 

 

paul_n
Shopify Staff
1817 199 432

One problem: your query has `tags` when it should be `tag`. With that fixed, you shouldn't need that second criteria in your condition. 

 

If you are saying that the tag isn't added, have you looked at the workflow run? That means it either didn't get the product you were expected (due to above issue), or your the data doesn't match your condition. Both of those should be shown in the run.

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.