"forloop" object unavailable in Flow templates despite documentation

bestrada
Tourist
12 2 1

flow-http-request.jpg

https://help.shopify.com/en/manual/shopify-plus/flow/examples#for-loop-examples

In 👆 your documentation, you write:

Text fields that support template variables also support for loops and the forloop object.

However, when I try to use it to produce a template it fails with the message "Unknown reference: forloop"

Here is the exact template I want in my http request body:

{
  "order": {
    "name": "{{ order.name }}",
    "id": {{ order.id }},
    "lineItems": [{% for li in order.lineItems %}
      {
        "quantity" : {{li.quantity}},
        "name" : "{{ li.name }}",
        "variantTitle" : "{{ li.variantTitle }}",
        "sku" : "{{ li.sku }}",
        "vendor" : "{{ li.vendor }}",
        "customAttributes": []
      }{% if true != forloop.last %},{% endif %}
      {% endfor %}],
    "createdAt": "{{ order.createdAt }}",
    "customer": {
      "displayName": "{{ order.customer.displayName }}"
    },
    "shippingAddress" : {
      "address1" : "{{order.shippingAddress.address1}}",
      "address2" : "{{order.shippingAddress.address2}}",
      "city" : "{{order.shippingAddress.city}}",
      "company" : "{{order.shippingAddress.company}}",
      "country" : "{{order.shippingAddress.country}}",
      "province" : "{{order.shippingAddress.province}}",
      "provinceCode" : "{{order.shippingAddress.provinceCode}}",
      "order.shippingAddress.zip" : "{{order.shippingAddress.zip}}",
      "formattedArea" : "{{order.shippingAddress.formattedArea}}",
      "countryCodeV2"  : "{{order.shippingAddress.countryCodeV2}}",
      "firstName" : "{{order.shippingAddress.firstName}}",
      "lastName" : "{{order.shippingAddress.lastName}}"
    }
  }
}

 

Reply 1 (1)

paul_n
Shopify Staff
939 128 225

The forloop should now work in Shopify Flow. We added support for it very recently. 

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.