# flow

Triggers a Shopify Flow workflow with a custom payload. Use this tag to integrate DataJet scripts with Shopify Flow automations. The flow needs to be created in Shopify Flow and the trigger name needs to be: Event Payload Trigger V2.

Read more about DataJet and Shopify Flow [here](/integrations/shopify-flow/v2.md).

```liquid
{% json my_payload %}
  {
    "customer_id": "{{ customer.id }}",
    "order_total": {{ order.total_price }},
    "action": "send_reward"
  }
{% endjson %}

{% flow payload: my_payload as result %}

{% if result.ok %}
  {% log "Flow triggered successfully" %}
{% else %}
  {% log "Failed to trigger flow" %}
{% endif %}
```

#### Syntax

```liquid
{% flow payload: payload_variable as result_variable %}
```

#### Parameters

| Parameter | Required | Description                                |
| --------- | -------- | ------------------------------------------ |
| `payload` | Yes      | Object containing data to send to the Flow |

#### Result Object

The result variable contains:

| Property | Type    | Description                               |
| -------- | ------- | ----------------------------------------- |
| `ok`     | boolean | `true` if Flow was triggered successfully |
| `body`   | object  | Response body from Flow trigger (if any)  |

#### Flow Receives

When triggered, the Shopify Flow receives:

| Field           | Description                        |
| --------------- | ---------------------------------- |
| `Script ID`     | The ID of the DataJet script       |
| `Script Handle` | The handle of the DataJet script   |
| `Run ID`        | The current execution run ID       |
| `Payload`       | Your custom payload as JSON string |

#### Use Cases

**Trigger post-order processing:**

```liquid
{% json order_payload %}
  {
    "order_id": "{{ order.id }}",
    "customer_email": "{{ order.email }}",
    "line_items": {{ order.line_items | map: "sku" | json }}
  }
{% endjson %}

{% flow payload: order_payload as result %}
```

**Send customer data to Flow for segmentation:**

```liquid
{% json customer_payload %}
  {
    "customer_id": "{{ customer.id }}",
    "total_spent": {{ customer.total_spent }},
    "orders_count": {{ customer.orders_count }},
    "tags": {{ customer.tags | json }}
  }
{% endjson %}

{% flow payload: customer_payload as result %}

{% unless result.ok %}
  {% log "Warning: Could not trigger customer segmentation flow" %}
{% endunless %}
```

**Chain DataJet script with Flow actions:**

```liquid
{% comment %} Process inventory data {% endcomment %}
{% assign low_stock_products = products | where_exp: "p", "p.inventory_quantity < 10" %}

{% if low_stock_products.size > 0 %}
  {% json alert_payload %}
    {
      "alert_type": "low_stock",
      "product_count": {{ low_stock_products.size }},
      "products": {{ low_stock_products | map: "title" | json }}
    }
  {% endjson %}

  {% flow payload: alert_payload as result %}
  {% log "Low stock alert sent to Flow" %}
{% endif %}
```

#### Notes

* Requires Shopify Flow to be installed and configured
* Each flow trigger consumes 1 credit
* Payload is automatically serialized to JSON
* Use Shopify Flow to handle notifications, tagging, or other actions based on the payload
* The Flow trigger uses DataJet's custom trigger "Event Payload Trigger V2"


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.datajet-app.com/liquid/tags/flow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
