Create Flow actions
Connect your app to Flow, so that your app receives data and information when a workflow action runs.
The example used in this task creates a trigger that starts a workflow 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 has access to the Internet, so that it can receive POSTs from Flow.
- A test store that has Flow installed. You can install Flow from the Shopify App Store.
Step 1: Add an action connector for Flow (Shopify Partner Dashboard)
To add an action to Flow, you need to create an action connector for your app. This action needs to contain the following information: * the fields that the merchant needs to complete when they add your action their workflows * the URL that Flow needs to use to send (POST) the contents (JSON payload) of the action to your app.
To create an action for Flow:
In the Partner Dashboard, open Apps and then click your test app.
Click the Shopify Flow tab and then click Add action:
Type a title and description for your action. For example, enter Log and Logs messages to the console respectively.
In the Action Preview area, you can see how the title and action will appear to your merchants when they are choosing actions in Flow.
Type the URL where the JSON payload will be sent to your app.
Click Create field and create the fields that will appear in Flow when your merchant chooses your app action. For example, to create a field for the merchant to send a message to your app add the following values:
Option Value Field name
Input type Text (single line) Label The APP Message Additional description Message to log to the APP’s console.
In the Payload preview area, you can see the data model that Flow will use in the JSON payload that it sends to your app.
- Click Save.
Step 2: Add support for your action in your app
After you create the action in the Partner Dashboard, you need to add a service to your app to listen for the JSON payload that Flow will send. For security reasons, your service should enforce a hash-based message authentication (HMAC) header verification that uses the API secret key that you created when you configured your app.
When your action runs in a workflow, Flow POSTs the contents (JSON payload) of the action to the URL that you entered when you created the action in the Partner Dashboard. When your app receives the POST request, the app processes it. For example, you app could receive the request, and output the message in the payload to a console in your app.
Step 3: Test your action in a workflow (Flow)
Now that you’ve created an acton in the Partner Dashboard and added support for it in your app, you can test it in Flow. In your test store, create a workflow that uses the action that you created for your app:
In your test store, install your app.
In your test store, create a Flow workflow that uses your action.
In your test store, trigger the workflow. For example, create an order.
When this workflow completes, the message that you added when you created the workflow appears in your app’s server console.