Create Shopify Flow triggers

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

When you create a trigger for Shopify Flow, you define the properties that your app will send to Shopify Flow.

Guidelines

Keep the following information in mind when you create your triggers:

  • When you create a trigger, the payload that you send to Shopify Flow needs to be less than 1 MB.

  • Triggers have the same API call limits as the Shopify API.

Before you begin

Make sure that you have the following:

  • A test web server that you can use to send information to Shopify Flow. You can use an existing web server. This web server needs to be able to POST content to Shopify Flow.
  • A test app that works with the test web server.
  • A test store that has Shopify Flow and the test app installed.

Before you can create a trigger, you need to enable the Shopify Flow extension area in your Partner Dashboard.

The example used in this task creates a customized trigger for Shopify Flow that starts when the temperature in a city changes.

Step 1: Create a trigger in the Shopify Partner Dashboard

The example used in this task creates a trigger that sends weather information (temperature) to Shopify Flow when the temperature in a city changes.

  1. In the Shopify Partner Dashboard, open the Shopify Flow app extension.
    1. Click Apps and then open your test app.
    2. Click Extensions and then click Shopify Flow. If you don't see Shopify Flow listed under Extensions, then you need to enable the Shopify Flow extension area to your app.
  2. Click Add trigger, and enter a title and description for your trigger. For example:
    Field Content to enter
    Trigger title: Weather changes
    Trigger description: Trigger when the weather changes
  3. Copy the GraphQL endpoint (https://{SHOP}/admin/api/graphql.json) that appears under the Trigger description field to a text file. Your app will use this endpoint to send your POST to Shopify Flow.
  4. Click Add property, choose a data type, and create the properties that will appear in Shopify Flow when your merchant chooses your trigger. For example, create two properties that contain the following values.

    Property 1
    • Data type: Short Text
    • Field name: City location
    • Label: City where the weather changed
    Property 2
    • Data type: Number
    • Field name:Temperature
    • Label: Temperature in Fahrenheit (rounded to the nearest whole number)
    These properties appear in Shopify Flow as conditions that your merchants can use when they use your trigger. Shopify Flow also uses these properties to create corresponding Liquid template variables for your merchants to use in workflow actions. When it creates template variables for these properties, Shopify Flow condenses the property names by removing spaces and changing the case of the first letter in each word. For example, {customerEmail}.
  5. Click Save.

Step 2: Add support for your trigger in your web server

In your web server, 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 trigger 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 triggering a weather change could have the following resource:
"resources": [
  {
    "name": "Weather changes",
    "url": "http://www.example.com/weather/toronto"
  }
]
  • The POST needs to use the GraphQL 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 same one that appeared in the Partner Dashboard when you created your trigger.)

The following is an example of a POST body:

mutation
{
  flowTriggerReceive(body:"{
    \"trigger_title\": \"Weather changes\",
    \"resources\": [
      {
        \"name\": \"Weather changes\",
        \"url\": \"http://www.example.com/weather/toronto\"
      }
    ],
    \"properties\": {
      \"City location\": \"Toronto\",
      \"Temperature\": \"30\"
    }
  }") {
    userErrors {field, message}
  }
}

Step 3: Test your trigger by creating a workflow

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

  2. In your web server, 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\": \"Weather changes\",
    \"resources\": [
      {
        \"name\": \"Weather changes\",
        \"url\": \"http://www.example.com/weather/toronto\"
      }
    ],
    \"properties\": {
      \"City location\": \"Toronto\",
      \"Temperature\": \"30\"
    }
  }") {
    userErrors {field, message}
  }
}'

When Shopify Flow receives the POST from your app, any workflow that contains your trigger will start.

Learn more

Sign up for a Partner account to get started.

Sign up