Search documentation...

K
ChangelogBook a demoSign up

Handling webhooks

A common use case for functions is cleaning up webhook data from other tools so that they may be ingested into your warehouse, or forwarded to other tools.

These webhooks usually contain event data that are helpful for building a full profile of your users. For example, Shopify has webhooks for when users check out, and Iterable has webhooks for when users open emails.

To set this up, you can create a Webhook Source and add it to your tool that emits events. You can then process the raw webhook data using Functions.

For example, your code might look something like:

async function transformEvents(events) {
  return events.map((event) => ({
    ...event,
    type: "track",
    event: event.event,
    messageId: event.messageId,
    properties: {
      ...event.properties.body.dataFields,
      email: event.properties.body.email,
    },
    anonymousId: event.properties.body.userId
      ? null
      : event.properties.body.email,
    userId: event.properties.body.userId,
  }));
}

Ready to get started?

Jump right in or a book a demo. Your first destination is always free.

Book a demoSign upBook a demo

Need help?

Our team is relentlessly focused on your success. Don't hesitate to reach out!

Feature requests?

We'd love to hear your suggestions for integrations and other features.

Last updated: Jul 29, 2024

Was this page helpful?