Create Shopify Flow triggers

Connect your app to Shopify Flow, so that events that occur in your app can trigger workflows.

The example used in this task creates a customized trigger for Shopify Flow that starts when a customer is added to a campaign in your app.

Before you begin

Make sure that you have the following:

  • A test app that you can use to send information to Shopify Flow. You can use an existing app. This app needs to be able to POST content to Shopify Flow.
  • A test store that has Shopify Flow installed. You can install Shopify Flow from the Shopify App Store.

Step 1: Create a trigger connector for Shopify Flow (Shopify Partner Dashboard)

To create a trigger for Shopify Flow, you need to add a trigger connector to your app. In this connector, you describe the properties that your app will send to Shopify Flow.

To create a trigger connector for Shopify Flow:

  1. In the Partner Dashboard, open Apps and then click your test app.

  2. Click Extensions > Shopify Flow:

    Shopify Flow listed under Extensions
    If you don't see Shopify Flow, then you need to add the extension to your app.

  3. Click Add trigger.

  4. Enter a title and description for your trigger. For example, enter Subscribed customer and A new customer has subscribed to the subscription campaign respectively.

  5. Click Add property and choose the data type for the data that your app will send to Shopify Flow. For example, choose Email to send an email address.

  6. Enter the name and description for the property. For example, enter Customer email and Customer contact email address respectively.

  7. Click Save.

Step 2: Add support for your trigger in your app

In your app, add the functionality that will post an HTTP request to Shopify Flow and use the GraphQL mutation flowTriggerReceive. This POST needs to be less than 1 MB and it needs to contain the following content in its body:

  • the name of the trigger
  • the property information that you defined when you created the connector for your app
  • the access token for your merchant’s store
  • a hash-based message authentication (HMAC) header that uses the API secret key associated with your app
  • the name and URL of the resource involved in the event that sends the trigger information to Shopify Flow. These details will appear in the logs in Shopify Flow, so that you and your merchant can use them when troubleshooting. For example, a resource that is involved in campaign subscriber event could have the following resource:
"resources": [
        {
            "name": "John Doe",
            "url": "http://www.example.com/customers/20185"
        }
  • The POST needs to use the webhook endpoint https://{STORE}.myshopify.com/admin/api/graphql.json, where {STORE} refers to the store that has a workflow that uses your trigger. (This URL is the one that appeared in the Partner Dashboard when you created your trigger connector.)

The following is an example of a POST body:

mutation
{
    flowTriggerReceive(body:"
    {
      "trigger_title": "Subscribed customer",
      "resources":
      [
      {
            "name": "John Doe",
            "url": "http://www.example.com/customers/20185"
      }
      ],
     "properties":
      {
        "Customer email": "myemail@myemaildomain.com",
      }
    }")
    {
    userErrors {field, message}
    }
}

Step 3: Test your trigger by creating a workflow (Shopify Flow)

Now that you’ve created a trigger connector and have added support for it in your app, you can test it in Shopify Flow.

To test your trigger:

  1. In your test store, install your app.

  2. In your test store, create a workflow that uses the trigger that you created for your app.

  3. In your Shopify admin, open Shopify Flow and create a workflow that uses your trigger.

  4. In your app, run the event that sends the trigger information to Shopify Flow. In a test environment, you can run a command to send the trigger information to your test store:

curl -X POST "https://johns-apparel.myshopify.com/admin/api/graphql.json" \
-H "Content-Type: application/graphql" \
-H "X-Shopify-Access-Token: 555555555555555" \
-d '
mutation
{
    flowTriggerReceive(body:"{
    \"trigger_title\": \"Subscribed customer\",
    \"resources\": [
         {
            \"name\": \"John Doe\",
            \"url\": \"http://www.example.com/customers/20185\"
        }
    ],
    \"properties\": {
         \"Customer email\": \"myemail@myemaildomain.com\"
    }
    }") {
    userErrors {field, message}
    }
}'

When Shopify Flow receives the POST from your app, workflows that use your trigger start.

Learn more

Sign up for a Partner account to get started.

Sign up