# V2

The second version of the DataJet / Shopify integration leverages the latest updates to the Shopify Flow integration, such as:

* Structured data in event triggers
* Processing responses returned to action triggers

Additionally, DataJet flow event triggers now include context information, such as:

* Script ID
* Run ID
* Script handle

### Event trigger

To start a flow from DataJet, you will need to complete two steps:

1. In DataJet, create a script that triggers the flow using the `flow_v2` filter.
2. In Shopify Flow, create a flow with the `Event Payload Trigger V2`

A sample script to trigger the flow is:

```
{% json payload %}
  {
    "name": "Mat",
    "age": 32
  }
{% endjson %}
{% flow payload:payload as result %}
{% log result %}
```

To create a Shopify Flow start by adding `Event Payload Trigger V2`:

<figure><img src="/files/fffnvlkchzcATkPL9JpX" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
If you have multiple flows responding to the same event - all flows are triggered.
{% endhint %}

After the event trigger block, you might want to add an "if" block to check the Script ID and ensure you only respond to events coming from a specific script:

<figure><img src="/files/ECT0tC1kS76pBcOTEWKd" alt=""><figcaption></figcaption></figure>

In the example above, we also log the payload passed to the flow from DataJet. This payload will be passed as stringified JSON. This is why we use a "Run code" block next to parse the stringified JSON into JSON:

<figure><img src="/files/XTX2uvpJXCVtZ5GuYiEA" alt=""><figcaption></figcaption></figure>

After this, we can access our payload properties in the next blocks using the following syntax:`{{runCode.payload.name}}`.

The flow above can be easily imported using this file (after importing, update the Script ID in the second block to match your script ID).

{% file src="/files/sL4D75hw5CddJFfElkdq" %}

### Action trigger

With Flow action triggers, you can trigger any script in DataJet. Depending on the outcome of the script execution, you can return either a success or error response to Shopify Flow and take corresponding actions.

The following two steps need to be completed:

1. In DataJet, create an HTTP script
2. In Shopify Flow - add the `Action Trigger V2` trigger

To create an HTTP script, select the "Add new HTTP script" button from the left-hand side navigation in DataJet. Next, you can use the following sample code:

```
{% assign flow_payload = request.body.properties.payload | default: "null" | parse %}

{{ flow_payload.email | log }}

{% json response %}
  {
    "body": {
      "return_value": {
        "status": "SUCCESS",
        "message": "OK"
      }
    }
  }
{% endjson %}
```

The code above reads the `email` property sent through Action Trigger V2 and logs it. After that, we return a success response to Shopify Flow. If you want to return an error response, replace `SUCCESS` with `ERROR`. Use the `message` field to send additional information.\
\
Your sample flow could look like this:

<figure><img src="/files/UNohuANhtWeijTR773Zb" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Replace Task ID with your script id from DataJet dashboard.
{% endhint %}

The flow above monitors changes to customer tags. When a tag is added, it sends a payload to DataJet with the customer's email. Next, if it receives a success response, it logs a success message; otherwise, it logs an error message.\
\
Above flow can be imported with this file:

{% file src="/files/8XEUobi3VXzTk2xMIpfp" %}

{% hint style="info" %}
The flow waits 10 seconds for an action response. After this time, the action resends the request. This is why it is important to ensure that your DataJet script processes the request in less than 10 seconds. You can use the run filter to delegate the logic to another task.
{% endhint %}


---

# 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/integrations/shopify-flow/v2.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.
