Trigger a Zapier task with Discourse Webhooks

Want to use Discourse Webhooks to trigger a task via Zapier? Let’s get started!

:bulb: Tip: Zapier now has an official Discourse integration 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 below.

Create a Discourse Webhook

Create a new Zap

Look for this button on Zapier dashboard:

Set up Trigger

Set up Action on Zapier

Turn on the Zap

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

:tada:


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”
  2. Click “Catch Raw Hook”
  3. Follow the remaining steps to configure the trigger normally.

Once the trigger is configured, add a filter.

  1. Click “Add a Step”
  2. Click “Filter”
  3. Click “Save and Continue”
  4. Select “Headers Http X Discourse Event” from the first dropdown.
  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”:

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”:

Scroll down the page to see a code input:

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:

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:

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 documentPerform check on document:
32 лайка