Why isn't my liquid code working in Flow?

Topic summary

Users are encountering errors when trying to use Liquid code in Shopify Flow, specifically receiving “invalid variable” messages when attempting to access order line items.

Core Issue:

  • Flow Liquid syntax differs from storefront Liquid syntax
  • The correct variable name is order.lineItems (not order.line_items)
  • Array items cannot be accessed using bracket notation like options[0] or options[1]

Key Solution Provided:

  • Use Flow’s “Add a variable” feature to identify correct syntax
  • Loop over arrays using {% for li in order.lineItems %} instead of direct indexing
  • Reference Shopify’s Flow-specific documentation rather than general Liquid docs

Remaining Problem:
One user reports that even when using the exact syntax from “Add a variable” (including lineItems_item), they still receive invalid variable errors. This suggests a potential inconsistency between Flow’s variable suggestion tool and what the system actually accepts.

The discussion remains open with the last reported issue unresolved.

Summarized with AI on October 24. AI used: claude-sonnet-4-5-20250929.

Can anyone tell me why this code refuses to be accepted by Shopify Flow please?

{% for line_item in order.line_items %}
{% if line_item.product.metafields.availability contains ‘NOT Available’ or line_item.product.metafields.logistics contains ‘Item is not available to order’ %}
{{line_item.sku}}
{% endif %}
{% endfor %}

I get the error:

  • “line_items” is invalid. Replace this variable.

Hey @vanillamt ,

It looks like the error message is indicating that the variable “line_items” is not valid and needs to be replaced.

Some possible causes of this error could include:

  • “line_items” is not a valid variable within the context of your code
  • There is a typo in the variable name, and it should be “line_item” instead
  • You are using an outdated version of Shopify’s Liquid template language and the variable name has been changed or deprecated.

I would recommend double-checking the variable name and making sure it is spelled correctly and that it is a valid variable in the context of your code. Also, check the version of the liquid template, if it is outdated, update it. Also, you can check Shopify’s documentation for the version you’re using to ensure that the variable is still supported.

Same problem with this code

  • {% for item in order.lineItems_item %} {% if item.title contains ‘XX’ %} {% assign aa= item.variant.options[0] %} {% assign bb= item.variant.options[1] %} {% assign cc= item.variant.options[2] %} XX{{ aa }}{{ bb}}{{ cc}} {% endif %} {% endfor %}

So first, Flow liquid is not same as storefront liquid (see https://help.shopify.com/en/manual/shopify-flow/reference/variables). Use “Add a variable” to gauge the syntax. So “order.line_items” is “order.lineItems” in Flow.

Second, you cannot access array items that way, like “item.variants.options[1]”. You can loop over arrays to get their items.

Finally, I’m not sure where you got “order.lineItems_item” but that’s not a field name. To access lineItems, typically you would use this loop:

{% for li in order.lineItems %}
{% if li.title == "something" %}
print out something
{% endif %}
{% endfor %}

I am running into this issue too - I used “Add a variable” to access what variables are available in the order, and am using what that tool spit out

{% tablerow lineItems_item in order.lineItems cols: 3 %}
{{lineItems_item.id}}
{{lineItems_item.name}}
{{lineItems_item.quantity}}
{% endtablerow %}

But I keep getting a message saying that lineItems_item is an invalid variable. If I change that to anything else, I get the same error message.

Hello @bugClip8229 ,

I hope you are well!

Can you please provide the screenshot where you are adding the code?

Tablerow is not a supported in Flow, so that error is a red herring