Transforming Webhooks responses with Zapier

  • 31 March 2017
  • 0 replies

Userlevel 7

Looker’s scheduled webhooks have limitless applications. One powerful way to use them is with Zapier.

Zapier allows you to mash together modular blocks of pre-defined functionality in a point & click way. This mashup is called a Zap, and once you build it in Zapier’s UI, if you select webhooks as the “trigger”, the Zap will have a URL that you can paste into Looker’s schedule to kick off the Zap whenever the schedule runs.

But what if the JSON output webhook is not exactly what you need? Maybe you have [{"service.tier":"premium","orders.status":"complete", "orders.count":500}, ...], but you want {"premium":{"complete":500},...},...} . This will walk you through setting up a transformation step using arbitrary javascript.

We’ll start at . From here, “Create a New Web Builder App”. Note that here we are creating an App (containing one Trigger) that you or others can then use as one component of a Zap, rather than a Zap itself.

For now, we’ll skip Authentication since the URL endpoint of the webhook can simply be kept secret.

The first important part of your app is the Trigger definition. First fill out the name and metadata, using any “key” you want, but note the key because we’ll use it in a later step. After the basic Trigger metadata, Zapier will ask you to set up Trigger Fields. These are essentially parameters that will be prompted to the person that builds a Zap from this Trigger. For now, skip this step, as it will make more sense once you have written your code. The last thing to do is to specify the source of the trigger - “Static Webhook”. Once you’re done, you should have something like this:

Next, scroll down to Scripting, and click Edit code. You’ll be taken to a code editor. The full documentation is here, but for our webhook scenario, we just need to declare one property on the Zap object, whose name should be the key from our Trigger + _catch_hook , like so:

The property should provide the function that we want Zapier to run on the incoming webhook request. This sample code below takes an array of records and transforms them into a hierarchical object:

var Zap = {
as_object_catch_hook: function(bundle) {
var byKeys=( ||
bundle.trigger_fields.byKeys ||
var ofKeys=(
bundle.cleaned_request.querystring.of ||
bundle.trigger_fields.ofKeys ||

return objByOf(,byKeys,ofKeys);

function set(obj,path,val){
var head=path[0];
return obj;
function get(obj,keys){
if(!keys){return obj;}
if(!keys.reduce){return obj[keys];}
return keys.reduce(function(accum,x,i){
return accum;

function objByOf(arr,byKeys,ofKeys){
byKeys=( ? byKeys : [byKeys]);
return arr.reduce(function(accum,x,i){
return set(accum,{return get(x,k);}),
byKeys.length? {} : []);

In this example, our script needs to know which fields to group by (and optionally which fields to keep at the “leaf” level of our hierarchy). So, we pull in these values from one of two sources, the request querystring, or more importantly bundle.trigger_fields What is this? It’s an object representing the values that a user can provide while configuring a Zap with our Trigger. In our example, we know we want to collect two parameters for our script to run. We can go back to our Trigger definition and declare these fields:

Testing our App to build a Zap

Once you’ve saved your script, you can now test this out. In a new tab, head over to and click “Make a zap”. Since your App is private by default until you publish it, you’ll need to be signed in, but if you are, you should be able to find your App to choose as a trigger:

When you choose it (and select the only Trigger we’ve made available in our App), you’ll then be prompted to provide values for the trigger fields. At this point, you can start to see the reusable value of this Zap, which can be used in a similar way for many different Looks/datasets.

Before you proceed to your actions, Zapier will want you to test the Trigger:

Copy the URL, and then head over to Looker. From your Look, click “Schedule…” from the gear menu, choose Webhook as the destination, paste in the URL, choose “Inline JSON” as the format, and click “Test”

Wait some time for the Look to finish running, and then back in Zapier, click to continue and you should now see this:

You can then continue on to use whichever Zapier action you had in mind, with the input data transformed exactly as you want it.

0 replies

Be the first to reply!