Unpublish a product by reading product id from custom line item properties

Hello

I am trying to run a task in Flow to unpublish a product when a draftOrder is created, due to lineitems being custom, we cannot use the standard productId on the line item to unpublish the product so I am thinking if can store productId and somehow can use it to unpublish the product?

Below is my Liquid code in “Select product” section, which outputs the ProductId correctly but we still get “Exception: Invalid Shopify Global ID: gid://shopify/Product/9867160289561” error when the Flow runs, any idea what is the correct syntax for returning productId from “Select product” section?

{% for customAttributes_item in lineItemsForeachitem.customAttributes %}
{% if customAttributes_item.key == “productId” %}
gid://shopify/Product/{{customAttributes_item.value}}
{% break %}
{% endif %}
{% endfor %}

It’s hard to tell exactly where you entered this (maybe you are overriding the resource for an action?), but it’s possible that you have whitespace around the ID, or that you’ve entered a variant ID and not a product ID.

To remove whitespace before and after a liquid tag, you can use hyphens like {%- and -%)

ProductId is correct,
Here is where I am entering it, I tried following but that gives syntax error, so not sure

gid://shopify/Product/{%- customAttributes_item.value -%}

Found it was not the space but line breaks around, putting liquid code without any line breaks did output the ProductId correctly

{% for customAttributes_item in lineItemsForeachitem.customAttributes %}{% if customAttributes_item.key == “productId” %}gid://shopify/Product/{{customAttributes_item.value}}{% break %}{% endif %}{% endfor %}