# Trigger a Zapier task with Discourse Webhooks

**URL:** https://meta.discourse.org/t/trigger-a-zapier-task-with-discourse-webhooks/56753
**Category:** Integrations
**Tags:** webhooks, how-to, tasks, zapier
**Created:** [February 1, 2017, 10:11pm UTC](https://meta.discourse.org/t/trigger-a-zapier-task-with-discourse-webhooks/56753 "2017-02-01T22:11:22Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [February 1, 2017, 10:11pm UTC](https://meta.discourse.org/t/trigger-a-zapier-task-with-discourse-webhooks/56753/1 "2017-02-01T22:11:22Z")

</div>

![](https://global.discourse-cdn.com/meta/original/3X/5/c/5c75173876c8457037359eb056eff8e2392fa9d7.png)

Want to use Discourse Webhooks to trigger a task via [Zapier](https://zapier.com)? Let’s get started!

> 💡 **Tip:** Zapier now has an [official Discourse integration](https://zapier.com/apps/discourse/integrations) with built-in triggers and actions (e.g. “New Post”, “Create Post”). For common use cases, this is simpler than configuring generic webhooks manually. The guide below covers the manual webhook approach, which gives you more flexibility and access to all Discourse event types.

Zapier requires a trigger and an action. In this howto the trigger will be a Discourse Webhook and the action will be to send an email.

## Send an Email on any User event

We will now set up a Zap to send email on any user event (e.g. when a user is created, approved, updated, logged in, logged out, suspended, and more). To trigger on a _specific_ user event, see [Trigger on a _specific_ user event](https://meta.discourse.org/t/discourse-webhooks-and-zapier/56753#heading--specific-event) below.

### Create a Discourse Webhook

- Create a new [Discourse Webhook](https://meta.discourse.org/t/setting-up-webhooks/49045) for user event

### Create a new Zap

Look for this button on Zapier dashboard: ![](https://global.discourse-cdn.com/meta/original/3X/6/e/6e7a8d5ef029db6eb3f2115b3b89bfb1c02269f8.png)

### Set up Trigger

- Select Webhook as Trigger. Look for:

- Choose Trigger

- You can skip “Set up Webhooks by Zapier Hook” step.

- Test Trigger

### Set up Action on Zapier

- Select Email as Action. Look for:

- Press “Save + Continue”

- Set Up Email Template

### Turn on the Zap

 ![](https://global.discourse-cdn.com/meta/original/3X/8/0/80659f15927c7052faebb7ec0285266f8f32ef1d.png)

That’s it, now you will receive an email for every user event. The full list of user events that can trigger a webhook is:

| Event Name | Description |
| --- | --- |
| `user_created` | A new user account is created |
| `user_approved` | A user is approved |
| `user_updated` | A user profile is updated |
| `user_logged_in` | A user logs in |
| `user_logged_out` | A user logs out |
| `user_confirmed_email` | A user confirms their email |
| `user_destroyed` | A user account is deleted |
| `user_suspended` | A user is suspended |
| `user_unsuspended` | A user is unsuspended |
| `user_anonymized` | A user account is anonymized |

🎉

* * *

## Trigger on a _specific_ user event

Want to only send emails for a specific user event, perhaps only on account creation, but not on update? Use the “Catch Raw Hook” trigger.

1. Click “show less common options”  
 ![image](https://global.discourse-cdn.com/meta/original/3X/3/2/3250f2fed24dfe46351b15893a0e10600a6c3c42.png)
2. Click “Catch Raw Hook”  
 ![image](https://global.discourse-cdn.com/meta/original/3X/a/b/ab3a97930ee87a022d0af465595688efefb9434b.png)
3. Follow the remaining steps to configure the trigger normally.

Once the trigger is configured, add a filter.

1. Click “Add a Step”  
 ![image](https://global.discourse-cdn.com/meta/original/3X/c/1/c1ab83e0cfa6dfe0ef0596f557eacf4b27b1abd9.png)
2. Click “Filter”  
 ![image](https://global.discourse-cdn.com/meta/original/3X/d/4/d4c56afa511e7d63079a1a269a2f22a3226ed8f8.png)
3. Click “Save and Continue”
4. Select “Headers Http X Discourse Event” from the first dropdown.  
 ![image](https://global.discourse-cdn.com/meta/original/3X/5/4/548dd0ba9a7c9343a2672e63d0316dedd0c25c94.png)
5. Select “(Text) Exactly matches” from the second dropdown.
6. Enter the complete header you want to filter for (for example, `user_logged_out`).
7. If you want Zapier to run on multiple headers, click “+OR” and add them just like the first.
8. Click “Test & Continue”
9. Review the filter test, then click “Continue”

Once the filter is configured, configure your preferred action.

## Using the Full Webhook Header

To get access to the header, follow the follow the previous steps - select “Catch Raw Hook” and then add a filter. Configure the filter to only continue if the `Headers Http X Discourse Event` matches the event you are looking for.

The difficulty here is that the Catch Raw Hook passes the webhook’s raw body. The final action I’m using needs parsed data from the body. What is working for me is to add a Code action after the filter. On the Code Action modal, select “Run Javascript”:

 ![Screen Shot 2019-02-08 at 6.47.15 PM.png](https://global.discourse-cdn.com/meta/original/3X/0/c/0cf4aff77d6b2f2dc60728dfbdcf27f3e634fb41.png)

Zapier will create an `inputData` object that you can add named properties to. Add a name for your property in the left column. From the right column, select “Catch Raw Hook” from the dropdown menu, and then select “Raw Body”:

 ![Screen Shot 2019-02-08 at 6.54.55 PM.png](https://global.discourse-cdn.com/meta/original/3X/b/5/b5583d91bedca9842965002bce6455a3acab36ce.png)

Scroll down the page to see a code input:

 ![Screen Shot 2019-02-08 at 6.56.31 PM.png](https://global.discourse-cdn.com/meta/original/3X/6/8/68f736c87db3690238132ef0a3865b380e65a09e.png)

You then need to replace the sample code with some code that parses the Raw Body and returns an object that has the values you need for your final action. Here’s the code I’m using. The object it returns is being used by the Salesforce integration. Salesforce requires a last name, so if no last name exists, an error is returned:

```plaintext
const parsed = JSON.parse(inputData.raw);
if (parsed.user) {
  const user = parsed.user,
        name = user.name,
        userFields = user.user_fields;
  let firstName,
      lastName,
      company;
  
  if (name) {
    const splitName = name.split(' ');
    firstName = splitName[0];
    lastName = splitName[1]
    }
  if (userFields) {
    company = userFields['10'];
  }
  if (lastName) {
    return {id: user.id,
            username: user.username,
            lastName: lastName,
            firstName: firstName,
            email: user.email,
            company: company
           };
  } else {
    return {error: "Missing last name"}
  }
} else {
  return {error: "A user object was not returned"};
}

```

To avoid making a failed request in the final action, another Zapier filter can be added. Set that filter to only continue if the error field returned by the javascript does not exist:

 ![Screen Shot 2019-02-08 at 7.17.53 PM.png](https://global.discourse-cdn.com/meta/original/3X/a/8/a89c06363bc233573d7f7139930ad49ee1a58e65.png)

 ![Screen Shot 2019-02-08 at 7.18.18 PM.png](https://global.discourse-cdn.com/meta/original/3X/6/9/691bc0399808afea2eae0248d6f37fc6fb177c52.png)

You can then add your final action. For selecting the fields to be used in the final action, use the properties returned by the Run Javascript action.

> Last edited by @sam 2026-04-01T23:15:24Z
> 
> > **Check document**
> >
> > Perform check on document:

---

_[View the full topic](https://meta.discourse.org/t/trigger-a-zapier-task-with-discourse-webhooks/56753)._
