Webhook Source
Step-by-step guide to add a Webhook source in RudderStack.
RudderStack lets you add any source that supports a webhook and use it to send events to your preferred destination.
When you create a webhook source in the RudderStack dashboard, you get a write key associated with it. Use this write key in a webhook endpoint in the format: http://<DATA_PLANE_URL>/v1/webhook?writeKey=<SOURCE_WRITE_KEY> You can then add this webhook URL to any source. RudderStack receives the data according to the settings made in the source, creates the payload, and routes it to your specified destination.
You must also add User Transformations to transform the event data into a destination-specific format.

Adding a Webhook Source

This section details the steps involved in setting up a webhook source. As an example, we will configure Mailchimp as a source in RudderStack.
    Assign a name to the source, and click on Next.
    Your webhook source is now created, as shown below. Note the Webhook URL which will be added in the source platform.
    Then, add a destination in RudderStack and connect it to this webhook source. In this example, we will configure Google Analytics as a destination, as shown:
Follow our guide on How to Add a Source and Destination in RudderStack for more details.
    Next, add the webhook URL to your desired source platform. Remember that you can configure webhook sources only for the source platforms that support webhooks. The following image shows the webhook URL added in Mailchimp:
Remember to add and test your webhook URL.
    When the users perform any of the actions configured in the source, the platform will send the generated events to the webhook URL.
In this example, Mailchimp sends the updates under What type of updates should we send? (seen in the image above) as user events to the webhook URL with the content type application/x-www-form-urlencoded.
The content type can vary in case of other webhook sources.
    RudderStack then takes the data, creates the payload and sends it to Google Analytics.
You must also add User Transformations to transform the payload into a destination-specific format before sending it to the destination. Refer to the Payload Creation and Transformation section for more details.

Payload Creation and Transformation

This section details how RudderStack receives the data from the webhook source platform and creates the resulting payload.
Continuing with our Mailchimp example, suppose a customer subscribes to Mailchimp. Mailchimp then sends the following data to RudderStack:
1
type=subscribe&fired_at=2021-07-28+08%3A06%3A59&data%5Bid%5D=e2ff089583&data%5Bemail%5D=ruchira%40rudderlabs.com&data%5Bemail_type%5D=html&data%5Bip_opt%5D=115.187.35.152&data%5Bweb_id%5D=161912900&data%5Bmerges%5D%5BEMAIL%5D=name%40rudderlabs.com&data%5Bmerges%5D%5BFNAME%5D=Name&data%5Bmerges%5D%5BLNAME%5D=Surname&data%5Bmerges%5D%5BADDRESS%5D=&data%5Bmerges%5D%5BPHONE%5D=&data%5Bmerges%5D%5BBIRTHDAY%5D=&data%5Blist_id%5D=ec4689c266
Copied!
RudderStack receives this data and creates the following payload:
1
[
2
{
3
"type": "track",
4
"event": "webhook_source_event",
5
"rudderId": "044448e2-a674-426c-ba61-8341262babcc",
6
"messageId": "4379907d-689a-4e3a-a2f7-477e29a02299",
7
"properties": {
8
"type": [
9
"subscribe"
10
],
11
"data[id]": [
12
"e2ff089583"
13
],
14
"fired_at": [
15
"2021-07-28 08:06:59"
16
],
17
"data[email]": [
19
],
20
"data[ip_opt]": [
21
"115.187.35.152"
22
],
23
"data[web_id]": [
24
"161912900"
25
],
26
"data[list_id]": [
27
"ec4689c266"
28
],
29
"data[email_type]": [
30
"html"
31
],
32
"data[merges][EMAIL]": [
34
],
35
"data[merges][FNAME]": [
36
"Name"
37
],
38
"data[merges][LNAME]": [
39
"Surname"
40
],
41
"data[merges][PHONE]": [
42
""
43
],
44
"data[merges][ADDRESS]": [
45
""
46
],
47
"data[merges][BIRTHDAY]": [
48
""
49
]
50
},
51
"anonymousId": "d6597ba2-54db-4bd7-8769-86ac067b4178"
52
}
53
]
Copied!
You can then transform this payload according to the desired destination with the help of RudderStack's User Transformations feature.
A sample transformation is as shown below:
1
export function transformEvent(event) {
2
const updatedEvent = event;
3
const { properties } = event;
4
5
if (properties) {
6
updatedEvent.event = properties.type;
7
updatedEvent.userId = properties["data[email]"];
8
updatedEvent.properties.name = `${properties["data[merges][FNAME]"]} ${properties["data[merges][LNAME]"]}`;
9
updatedEvent.properties.phone = properties["data[merges][PHONE]"];
10
11
delete updatedEvent.properties["data[merges][PHONE]"];
12
delete updatedEvent.properties["data[merges][FNAME]"];
13
delete updatedEvent.properties["data[merges][LNAME]"];
14
}
15
16
return updatedEvent;
17
}
Copied!
The transformed payload is as shown:
1
{
2
type: 'track',
3
event: [
4
'subscribe'
5
],
6
rudderId: '044448e2-a674-426c-ba61-8341262babcc',
7
messageId: '4379907d-689a-4e3a-a2f7-477e29a02299',
8
properties: {
9
type: [
10
'subscribe'
11
],
12
'data[id]': [
13
'e2ff089583'
14
],
15
fired_at: [
16
'2021-07-28 08:06:59'
17
],
18
'data[email]': [
20
],
21
'data[ip_opt]': [
22
'115.187.35.152'
23
],
24
'data[web_id]': [
25
'161912900'
26
],
27
'data[list_id]': [
28
'ec4689c266'
29
],
30
'data[email_type]': [
31
'html'
32
],
33
'data[merges][EMAIL]': [
35
],
36
'data[merges][ADDRESS]': [
37
''
38
],
39
'data[merges][BIRTHDAY]': [
40
''
41
],
42
name: 'Name Surname',
43
phone: [
44
''
45
]
46
},
47
anonymousId: 'd6597ba2-54db-4bd7-8769-86ac067b4178',
48
userId: [
50
]
51
}
Copied!
RudderStack then sends this payload to your destination.

Contact Us

If you come across any issues while setting up and using webhook sources in RudderStack, feel free to contact us or start a conversation on our Slack channel.
Last modified 1mo ago