Using Liquid in generating an HTTP Body

NolanM
Shopify Partner
18 0 12

I'm attempting to use Shopify Flow to on trigger (Order Created or Order Paid) to send a JSON object to a 3rd party external service for additional processing.

 

Just wondering if anyone has run into the following issues and potential solutions with liquid:

1) Attempting to iterate over an order's list (items list, taxLines) with a For Loop, and the forloop object is does not seem to be available for consumption.

{
    "taxLines": [
        {% for taxLine in order.taxLines %}
        {
            "title": "{{taxLine.title}}",
        }{% unless forloop.last %},{% endunless %}
        {% endfor %}
    ]
}

(hopefully no typos), the Flow validator will fail this snippet. Remove forloop, and there is no syntax issue, but not valid JSON.

 

2) Defining variable tags. It looks like i can use assign, but I am unable to use the declared variable. Is there something I am misunderstanding?

{% assign some_var = "Pumpkin Spice" %}
{
    "drink": "{{some_var}}"
}

Any suggestions and comments welcome.

Thanks

-nolan

Replies 2 (2)

AnthonyKentris
Shopify Staff
33 15 16

Hi @NolanM, great question.

 

So you're using the HTTP request action at the end of your workflow, right?

 

You can do For Loops, and you can reach more about that in this Liquid support in Flow documentation. And on this examples page you can see an example of how to successfully use a For Loop. Looking at your code though, it looks like you're doing it correctly. I know a For Loop works in our email and Slack action, but I wonder if there is a blocker to executing on the HTTP request action.

 

As for your second question, have a look through the Liquid support documentation I sent above to double check if it's allowed.

 

I'll leave this question open as other experts might have some ideas here. In the meantime, it might also be valuable to reach out to our technical support team and this will be escalated to the right team for an answer. Good luck!

Anthony // Product Marketing Manager @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - Learn about Shopify Plus

NolanM
Shopify Partner
18 0 12

Hi @AnthonyKentris ,

 

For the first issue, its the usage of the forloop object in the unless block.

I am able to loop through a list, I am just not able to use the forloop object.

 

Its the same with the assign, i can declare the assigning of a property, but I am not able to use it anywhere.