Using Zapier to create workflows
How you can use reactions to trigger Zapier workflows from your domain events
Zapier provides workflows to automate the use of web applications together. It is often described as a translator between web APIs. This guide demonstrates how you can use Serialized Reactions to trigger Zapier workflows every time a specific event is stored in Serialized.
Our goal is to receive an email every time a CaptureCompleted
event of aggregate type payment
is stored in Serialized.
Setting up Zapier
Sign up or log in to Zapier and click Make a Zap.
Step 1 - Choose app
Click the "Webhooks by Zapier" icon and choose "Catch Hook" as "Trigger Event".
Click "Continue"
Step 2 - Customize webhook
Copy/write down the custom generated webhook that was URL generated for you.
Click "Continue"
Step 3 - Find Data / Test
Open a terminal/command prompt and send the following POST request:
curl -i https://hooks.zapier.com/hooks/catch/<your>/<key>/ \
--header "Content-Type: application/json" \
--data '
{
"value1": "Test1",
"value2": "Test2",
"value3": "Test3",
"value4": "Test4",
"value5": "Test5",
"value6": "Test6",
"value7": "Test7",
"value8": "Test8",
"value9": "Test9"
}
'
Go back to your browser window.
Click "Test and review" and make sure the POST request was received successfully.
Click "Done"
Step 4 - Select App and Event
Click the "Email by Zapier" icon and select "Send outbound mail" as "Event Action".
Click "Continue"
Enter your email address in the "To" field.
Enter a subject, eg. "Payment notification"
Now, click "Body" and choose "Value1" from the "Insert Data" dropdown.
Scroll down and click "Continue"
Step 5 - Activate and finish
Click "Skip test" and enable you Zap using the toggle at the bottom.
Step 6 - Creating the Serialized Reaction definition
We need to tell Serialized to subscribe to the feed created by the aggregate type payment
and to react to all
events of type CaptureCompleted
by POST:ing to our Zapier webhook.
The targetUri
should end with your generated webhook key you received in the previous steps.
Serialized Zapier integration supports up to nine variable values:
{ "value1" : "", "value2" : "" ... "value9" : "" }
.
Simple templating is supported and event data can be accessed using dot (.) notation.
curl -i https://api.serialized.io/reactions/definitions \
--header "Content-Type: application/json" \
--header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
--header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
--data '
{
"reactionName": "zapier-payment-notifier",
"feedName": "payment",
"reactOnEventType": "CaptureCompleted",
"action": {
"actionType": "ZAPIER_POST",
"targetUri": "https://hooks.zapier.com/hooks/catch/<your>/<key>/",
"valueMap": {
"value1": "Payment made by ${event.data.customerId} with amount ${event.data.amount}."
}
}
}
'
Step 6 - Store an event and trigger the workflow!
Now it’s time to trigger the Reaction and the Zapier workflow. Let’s post an event to Serialized!
curl -i https://api.serialized.io/aggregates/payment/cbb455e0-0d4c-4642-8b39-f7fa3f708d75/events \
--header "Content-Type: application/json" \
--header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
--header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
--data '
{
"events": [
{
"eventType": "CaptureCompleted",
"data": {
"customerId": "some-test-id-1",
"amount": 1234567
}
}
]
}
'
Open up your mailbox and voila!