Ingest events from a custom webhook source into RudderStack.
6 minute read
Apart from the Event Stream cloud sources, RudderStack also supports any other source that provides a webhook and lets you use it to send events to your preferred destinations.
Note the following:
RudderStack recommends using the webhook source only if your input data is not in the standard RudderStack event format. In such cases, you can write a transformation to convert the data into the standard event format.
To ingest events that follow the standard RudderStack event format, use an HTTP source instead.
Once the source is created, note the Webhook URL and use it to configure a webhook in the platform from where you want to ingest events.
Not all platforms support configuring webhook sources.
When the users perform any action configured in the source, the source platform automatically sends the generated events to the webhook URL.
RudderStack takes the data, creates the event payload, and sends it to the connected destinations after transforming them in the required format.
Get started
Go to your RudderStack dashboard and click Add Source. From the list of Event Streams sources, select Webhook.
Assign a name to your source and click Continue.
Toggle on the Put source request details in event context setting to include all the request details like headers, query parameters, method, URLs, etc. in the event payload. See Send source request details in event’s context section for more information.
Your webhook source is now created. Go to the Settings tab of the source and note the Webhook URL:
You must also connect an appropriate Transformation to this destination to transform the ingested event payload into the destination-specific format.
See the Use case section below for an end-to-end example.
After the setup is complete, configure the webhook in your source platform and specify the webhook URL obtained above. You can test and confirm if your webhook is working as expected by ingesting some events and using the Live Events functionality to view the events in real time.
Send source request details in event’s context
While setting up the webhook source, you can toggle on the Put source request details in event context setting to include all the request details like headers, query parameters, method, URLs, etc. in the event payload.
For existing webhook sources, go to the Configuration tab of the source, click the Update button and toggle on this setting.
See the following sections to understand how this setting impacts the payload creation and transformation:
This section covers an end-to-end use case that ingests events from Mailchimp into RudderStack by configuring a webhook and sends it to the Google Analytics destination.
Obtain the webhook URL by following the steps in the Get started section.
Configure a webhook and specify the webhook URL in Mailchimp. The following image shows the webhook URL added in Mailchimp:
As seen in the above image, Mailchimp sends the updates under Trigger on Events as user events to the specified webhook URL with the content type application/x-www-form-urlencoded.
The content type can vary in case of the other webhook sources.
How RudderStack creates the event payload
This section continues with the above use case containing the Mailchimp example and details how RudderStack receives the data from the webhook source and creates the resulting event payload.
Suppose a customer subscribes to Mailchimp. Mailchimp then sends the following data to RudderStack:
This section highlights how to transform the created event payload in a destination-specific format by leveraging RudderStack’s Transformation feature.
Make sure this transformation is connected to the destination where you want to send the data.
Case 1: No request details in event context
If Put source request details in event context setting is toggled off, then use the following sample transformation to transform the event payload:
If you have toggled on the Put source request details in event context setting, then you can modify the above transformation as follows:
You can write this transformation to use the values from the event’s context as per your requirement.
exportfunctiontransformEvent(event){constupdatedEvent=event// Notice we destructured context out of the event
const{properties,context}=eventif(properties){updatedEvent.event=properties.typeupdatedEvent.userId=properties["data[email]"]updatedEvent.properties.name=`${properties["data[merges][FNAME]"]}${properties["data[merges][LNAME]"]}`updatedEvent.properties.phone=properties["data[merges][PHONE]"]// Notice we populated these from context
// Make sure to enable "put request details" as indicated above to find these in context
updatedEvent.properties.customParam=context.query_parameters.query_param_testupdatedEvent.properties.userAgent=context.headers["User-Agent"]deleteupdatedEvent.properties["data[merges][PHONE]"]deleteupdatedEvent.properties["data[merges][FNAME]"]deleteupdatedEvent.properties["data[merges][LNAME]"]}returnupdatedEvent}
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.