Using IFTTT to create workflows

If This Then That, also known as IFTTT is a free web-based service that creates chains of simple conditional statements, called applets. This guide demonstrates how you can use Serialized Reactions to trigger IFTTT chains 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 IFTTT

Sign up or log in to IFTTT and click create.

Step 1 - Setup Webhooks service

Click the big plus sign (between "If" and "This") and choose "Webhooks" as "Service" and click "Connect".

Step 2 - Setup trigger

Choose "Receive web request" as trigger and enter the event name "payment_notification" and click "Create trigger".

Step 3 - Connect to Email service

Click the big plus sign (now to the right), choose the service "Email" and click "Connect".

Enter your email address and click "Send PIN".

Check your mailbox for the mail with the 4 digit PIN, enter it and click "Connect".

Step 4 - Setup email sending

Click "Send me an email".

Step 5 - Create action

Just keep the default suggestion for now and click "Create action".

Step 6 - Review configuration

Review the configuration, which should read something like: "If Maker Event "payment_notification", then Send me an email at you@email.com".

Click "Receive notifications when this Applet runs".

Click "Finish".

Step 7 - Find the Webhook URL

Click the "Webhooks" icon, to the left of the email icon, and then "Settings" in the upper right corner.

Notice the generated webhook URL! The last part of the URL contains your webhook key - this is the one we will use in our Serialized Reaction in the next step!

Step 8 - 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 IFTTT webhook. The targetUri should end with your generated webhook key you received in the previous step.

IFTTT supports up to three variable values:

{ "value1" : "", "value2" : "", "value3" : "" }.

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": "ifttt-payment-notifier",
    "feedName": "payment",
    "reactOnEventType": "CaptureCompleted",
    "action": {
      "actionType": "IFTTT_POST",
      "targetUri": "https://maker.ifttt.com/trigger/payment_notification/with/key/<your-key>",
      "valueMap": {
        "value1": "Payment made by ${event.data.customerId} with amount ${event.data.amount}."
      }
    }
  }
'

Step 9 - Store an event and trigger the workflow!

Now it’s time to trigger the Reaction and the IFTTT chain. Let’s post an event to Serialized!

curl -i https://api.serialized.io/aggregates/payment/24901bdf-156a-41ce-996d-fb8f78b6ae1b/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": 12345
           }
        }
     ]
  }
'

Open up your mailbox and voila!