If you use Zapier: best practices

Pro tips for using Zapier's Webhooks to make cool integrations happen

Support avatar
Written by Support
Updated over a week ago

If you are looking for a low development effort way to integrate EMS into your systems, we recommend Zapier as the intermediary layer.

Please note: This does not imply any official partnership with Zapier.

Here are some of the Zapier best practices when using EMS webhooks and APIs

1. Raw Hooks can better than a parsed one, if you know how to use them

When you set up a zap to receive a webhook and feel comfortable using Zapier's code blocks, consider using the Catch a raw hook option. This will prevent Zapier from flattening any arrays that are nested. eg: Opt-in lists in audience member webhook. The rawBody can then be parsed into JSON using a code block.

let output = JSON.parse(inputData.rawBody)

2. Iterating over a list

If an audience member is opted-in to 3 opt-in lists, you might want a zap to add them to 3 mailing lists. Most CRMs and email platforms we have encountered do not accept multiple list ids. So there is a need to be able to run steps of a zap for each object in the list.

But Zapier does not provide a direct way to iterate over a list of objects. Zapier, however, allows zaps to easily make HTTP calls including to the receiving hook of a different zap. You can use this feature to simulate a loop as described above. This set up involves setting up two zaps: an iterator and a data processor.

The iterator zap loops through the list in a code block and call the data processor zap to process each member of the list.

Example: Iterating over an array of opt-in lists

// The data processor Zap catch hook url
const otherZapUrl = '{REPLACE THIS WITH YOUR PROCESSOR WEBHOOK URL}'

// Parse raw hook as describe in step 1
let body = JSON.parse(inputData.rawBody);

let optInLists = body.payload.opt_in_lists;

// construct the body of the new request in any format you want
// Here it is being rebuilt with the email added to every list
optInLists.map(list => {
  list.email = body.payload.email
  fetch(otherZapUrl, {method: 'POST', body: JSON.stringify(list)})
    .then(() => {
    callback(null, [{status: 'ok'}]);
  });
});

Please let us know if you have any questions by emailing us at support@wearehearken.com

Did this answer your question?