Using ASP.NET WebHooks with IFTTT and Zapier to Monitor Twitter and Google Sheets

Henrik F Nielsen

With the latest drop of ASP.NET WebHooks we have added a generic JSON WebHook receiver, which can be used to receive WebHooks from services like IFTTT and Zapier. Both IFTTT and Zapier provide a huge number of integrations in areas such as productivity, automotive, blogging, CRM, commerce, project management, IoT, social, mobile, collaboration, and much more. For a full list, check out IFTTT channels and browse Zapier zaps.

A really cool thing about both IFTTT and Zapier is that they enable regular HTTP requests to be output of an integration. That is, you can build integrations that when something happens, a Web request is sent to some specified destination.

Here we’ll show how to leverage this to build two simple integrations – one with IFTTT and one with Zapier – and then use ASP.NET WebHooks to receive the result. For IFTTT we wire it up to Twitter monitoring when a tweet is sent, and for Zapier we wire it up to a Google Sheet monitoring when a row is added. These are of course just examples – the possibilities for integrations are endless!

Configuring Generic WebHook Handler

As usual, let’s first create an empty Web Application with Web API in Visual Studio which we will use for receiving WebHooks from IFTTT and Zapier. Btw, if you just want to look at the code then you can also check out this sample. Otherwise, continue by setting the project up for deployment in Azure by checking Host in the cloud:

EmptyProject

Install the Microsoft.AspNet.WebHooks.Receivers.Generic Nuget package. The registration happens exactly like in the blog Introducing Microsoft ASP.NET WebHooks Preview by adding this line to the WebApiConfig.Register method:

public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);

// Initialize Generic JSON WebHook receiver
config.InitializeReceiveGenericJsonWebHooks();
}
}

In this case we want the same receiver to handle both IFTTT and Zapier WebHooks which means that we need two WebHook URIs looking like this (one for IFTTT and one for Zapier):

https://<host>/api/webhooks/incoming/genericjson/i?code=1388a6b0d05eca2237f10e4a4641260b0a08f3a5
https://<host>/api/webhooks/incoming/genericjson/z?code=80ad19e357b01a04fe767067df7cd31b96a844e1

We achieve this by defining the MS_WebHookReceiverSecret_GenericJson application setting as follows:

<appSettings>
<add key="MS_WebHookReceiverSecret_GenericJson"
value="i=1388a6b0d05eca2237f10e4a4641260b0a08f3a5,z=80ad19e357b01a04fe767067df7cd31b96a844e1" />
</appSettings>
As stated in the blog Introducing Microsoft ASP.NET WebHooks Preview, the preferred way to do this is to set it in the Azure Portal. The ‘code’ parameter must be between 32 and 128 characters long and as usual, you should pick values that have high entropy. A good idea is to pick something like a SHA256 hash which you for example can get from FreeFormatter Online Tools For Developers.

Finally, we add a GenericJsonWebHookHandler.cs file containing the following class for processing the incoming WebHooks for both IFTTT and Zapier. Note how we use the ‘Id’ property to differentiate between the two:

public class GenericJsonWebHookHandler : WebHookHandler
{
public GenericJsonWebHookHandler()
{
this.Receiver = "genericjson";
}

public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
{
// Get JSON from WebHook
JObject data = context.GetDataOrDefault<JObject>();

if (context.Id == "i")
{
// Received a WebHook from IFTTT!
}
else if (context.Id == "z")
{
// Received a WebHook from Zapier!
}

return Task.FromResult(true);
}
}

Integrations using IFTTT’s Maker Channel

Setting up a recipe with IFTTT is fairly straight forward, but obviously you need an account with IFTTT. And just to avoid any confusion, to wire up to Twitter you also need a twitter account. Start by going to My Recipes, then IF, then Create a Recipe, and then this to set up the trigger part:

IFTTT-01

Look for the Twitter channel:

IFTTT-02

and select New tweet for you:

IFTTT-03

Wire it up to your twitter account and create the trigger:

IFTTT-04

Now select that for the action part:

IFTTT-05

Search for the Maker channel:

IFTTT-06

and select the Make a web request action:

IFTTT-07

Set URL to the first WebHook URI value from above, set the Method to ‘POST’ and Content Type to ‘application/json’.

IFTTT-08

Also, set the Body to something like this while being careful generating valid JSON – otherwise the WebHook receiver will reject it:

{ "Text": "{{Text}}", "Link": "{{LinkToTweet}}" }
 
Select Create Action and you should see something like this:
 
IFTTT-09

Integrations using Zapier’s WebHook Action

Setting up an integration with Zapier is equally simple, but of course you also need a Zapier account to get going and one for Google Drive to wire up to Google Sheets. Start by going to your dashboard and select Make a new Zap:

Zapier-01

Then for trigger search for Google Sheets as the trigger app:

Zapier-02a

Then pick New Spreadsheet Row as the trigger. Similarly, pick WebHooks by Zapier as the action app and then POST as the action:

Zapier-03

For this tutorial I created a Google Sheet with simple data like this:

GoogleSheet

Now add your Google Sheets account to the trigger part of the Zap in step 2:

Zapier-04

The WebHooks by Zapier action doesn’t require any account setup in step 3 so just continue to step 4:

Zapier-05

Select the particular sheet you want to monitor and pick the particular worksheet:

Zapier-06

Finally, set the URL to the second WebHook URI value from above and set the Payload Type to ’json’:

Zapier-07

In step 6 you can test out the zap but for now just go to step 7, enable the zap and get ready to try it out:

Zapier-08a

Trying it Out

Simply deploy your Web Application Project to Azure and try out the two integrations: To trigger the IFTTT integration, tweet from the account you registered, and for Zapier, add a row to the Google Sheet. For both IFTTT and Zapier there is a delay, at least in the free tier, for some minutes before changes cause a WebHook to fire. However, in both cases you can manually run the integration to cause it to fire.

If you attach the debugger and add a row to the Google Sheet you and then run the zap manually, you should see this show up in the debugger like this:

Zapier-09

Similarly, after you tweet you should see the same breakpoint getting hit but this time for the IFTTT integration.

That’s it – you can now build integrations using IFTTT and Zapier and get the result straight into ASP.NET using ASP.NET WebHooks.

Have fun!

Henrik

3 comments

Discussion is closed. Login to edit/delete existing comments.

  • Salim Shaik 0

    Hi,

    I have a asp.net website which supports social media logins(FB/Gmail/Linked-in).Oncw the user logs-in my website is storing in user’s third party app list on all these social sites. If user deletes my website(app) from his apps list,can we track that immidiately? Please suggest me on this.

  • Kehinde Adejoro 0

    Quiet informative and straight to point. Am currently working on an ASPNET core web API can u please help me on how integrate it with Zapier.. Will like to hear from you. thanks

  • NemoCapt 0

    Hi,
    I am having some problems with ASP.NET Webhook custom receiver for recieving “Push notification” from an internal service.
    Would be able to look at it provide some guidance or recommendations on where I am going wrong ?
    Details in this SO question : https://stackoverflow.com/questions/62298197/asp-net-webhook-receiver-test-failing

    Thanks,

Feedback usabilla icon