Relay Webhooks are a way to instruct SparkPost to forward messages sent to an inbound domain to a target url for your own consumption. Before you create a relay webhook, first create and configure an inbound domain. The Relay Webhooks API provides the means to create, list, retrieve, update, and delete a relay webhook. To consume event webhooks see Event Webhooks
{
"id": "12013026328707075",
"name": "Inbound Customer Replies",
"target": "https://webhooks.customer.example/replies",
"auth_token": "5ebe2294ecd0e0f08eab7690d2a6ee69",
"match": {
"protocol": "SMTP",
"domain": "example.com"
}
}
Unique ID
Relay webhook name
URL of the target to which to POST relay batches
Type of authentication to be used during POST requests to target.
Possible Values: none
, oauth2
Object containing details needed to request authorization token for OAuth 2.0. This is required when auth_type
is oauth2 and only grant_type of credentials is supported.
Authentication token to present in the X-MessageSystems-Webhook-Token
header of POST requests to target. Use this token in your target application to confirm that data is coming from SparkPost.
Restrict which inbound messages will be relayed to the target.
Object of custom HTTP headers to be used during POST requests to target.
The custom headers JSON object allows you to add up to five custom headers to your relay webhook. The custom_headers
object may only be up to 3,000 bytes in size, and must be formatted as an object with keys as strings or numbers. Headers already used by SparkPost will not be allowed, and SparkPost may also disallow some HTTP headers for security reasons.
Adding Custom Headers
When creating (POST) or updating (PUT) a Relay Webhook:
{
"custom_headers": {
"header1": "value1",
"header2": "value2"
}
}
Removing Custom Headers
When updating (PUT) a Relay Webhook:
{
"custom_headers": {}
}
The following fields will be included in each object posted to the relay webhook's target:
[
{
"msys": {
"relay_message": {
"content": {
"email_rfc822": "Return-Path: <me@here.com>\r\nMIME-Version: 1.0\r\nFrom: me@here.com\r\nReceived: by 10.114.82.10 with HTTP; Mon, 4 Jul 2016 07:53:14 -0700 (PDT)\r\nDate: Mon, 4 Jul 2016 15:53:14 +0100\r\nMessage-ID: <484810298443-112311-xqxbby@mail.there.com>\r\nSubject: Relay webhooks rawk!\r\nTo: you@there.com\r\nContent-Type: multipart/alternative; boundary=deaddeaffeedf00fall45dbhail980dhypnot0ad\r\n\r\n--deaddeaffeedf00fall45dbhail980dhypnot0ad\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\nHi there SparkPostians.\r\n\r\n--deaddeaffeedf00fall45dbhail980dhypnot0ad\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n<p>Hi there <strong>SparkPostians</strong></p>\r\n\r\n--deaddeaffeedf00fall45dbhail980dhypnot0ad--\r\n",
"email_rfc822_is_base64": false,
"headers": [
{
"Return-Path": "<me@here.com>"
},
{
"MIME-Version": "1.0"
},
{
"From": "me@here.com"
},
{
"Received": "by 10.114.82.10 with HTTP; Mon, 4 Jul 2016 07:53:14 -0700 (PDT)"
},
{
"Date": "Mon, 4 Jul 2016 15:53:14 +0100"
},
{
"Message-ID": "<484810298443-112311-xqxbby@mail.there.com>"
},
{
"Subject": "Relay webhooks rawk!"
},
{
"To": "you@there.com"
}
],
"html": "<p>Hi there <strong>SparkPostians</strong>.</p>",
"subject": "We come in peace",
"text": "Hi there SparkPostians.",
"to": [
"your@yourdomain.com"
]
},
"customer_id": "1337",
"friendly_from": "me@here.com",
"msg_from": "me@here.com",
"rcpt_to": "you@there.com",
"webhook_id": "4839201967643219"
}
}
}
]
The content parsed from the incoming message.
Email address used to compose the "From" header
SMTP envelope "MAIL FROM", matches "Return-Path" header address
SMTP envelope "RCPT TO"
ID of the relay webhook which triggered this relay message.
smtp
Protocol of the originating inbound message.
Customer ID of the customer that created the relay webhook.
POST /api/v1/relay-webhooks
{
"name": "Replies Webhook",
"target": "https://webhooks.customer.example/replies",
"auth_token": "5ebe2294ecd0e0f08eab7690d2a6ee69",
"auth_type": "oauth2",
"auth_request_details": {
"url": "http://client.example.com/tokens",
"body": {
"client_id": "CLIENT123",
"client_secret": "9sdfj791d2bsbf"
}
},
"custom_headers": {
"x-api-key": "abcd"
},
"match": {
"domain": "email.example.com"
}
}
{
"results": {
"id": "12013026328707075"
}
}
Create a relay webhook by providing a relay webhooks object as the POST request body.
Relay webhook name
URL of the target to which to POST relay batches. Only ports 80 for http and 443 for https can be set.
none
Type of authentication to be used during POST requests to target.
Possible Values: none
, oauth2
Object containing details needed to request authorization token for OAuth 2.0. This is required when auth_type
is oauth2 and only grant_type of credentials is supported.
Authentication token to present in the X-MessageSystems-Webhook-Token
header of POST requests to target.
Restrict which inbound messages will be relayed to the target.
Object of custom HTTP headers to be used during POST requests to target.
POST /api/v1/relay-webhooks/12013026328707075/validate
{
"results": {
"msg": "Test POST to endpoint succeeded",
"response": {
"status": 200,
"headers": {
"Content-Type": "text/plain"
},
"body": "OK"
}
}
}
The validation request sends an example batch to the target URL, validates that the target responds with HTTP 200, and returns information on the response received from the target.
GET /api/v1/relay-webhooks/12013026328707075
{
"results": {
"name": "Replies Webhook",
"target": "https://webhooks.customer.example/replies",
"auth_token": "5ebe2294ecd0e0f08eab7690d2a6ee69",
"auth_type": "oauth2",
"auth_request_details": {
"url": "https://oauth.myurl.com/tokens",
"body": {
"client_id": "<oauth client id>",
"client_secret": "<oauth client secret>"
}
},
"custom_headers": {
"x-api-key": "abcd"
},
"match": {
"protocol": "SMTP",
"domain": "email.example.com"
}
}
}
Retrieve a specific relay webhook by specifying the webhook ID in the URI path.
PUT /api/v1/relay-webhooks/12013026328707075
{
"name": "New Replies Webhook",
"target": "https://webhook.customer.example/replies",
"auth_token": "A different auth token",
"auth_type": "none",
"custom_headers": {
"x-api-key": "abcd"
},
"match": {
"domain": "email.a-different-domain.com"
}
}
{
"results": {
"id": "12013026328707075"
}
}
Update a relay webhook by specifying the webhook ID in the URI path.
Relay webhook name
URL of the target to which to POST relay batches. Only ports 80 for http and 443 for https can be set.
Authentication token to present in the X-MessageSystems-Webhook-Token
header of POST requests to target.
Type of authentication to be used during POST requests to target. Read more about webhook authentication.
Possible Values: none
, oauth2
Object containing details needed to request authorization token for OAuth 2.0. This is required when auth_type
is oauth2 and only grant_type of credentials is supported.
Restrict which inbound messages will be relayed to the target.
Object of custom HTTP headers to be used during POST requests to target.
DELETE /api/v1/relay-webhooks/12013026328707075
// Empty response body
Delete a relay webhook by specifying the webhook ID in the URI path.
GET /api/v1/relay-webhooks
{
"results": [
{
"id": "12013026328707075",
"name": "Replies Webhook",
"target": "https://webhooks.customer.example/replies",
"auth_token": "5ebe2294ecd0e0f08eab7690d2a6ee69",
"auth_type": "oauth2",
"auth_request_details": {
"url": "https://oauth.myurl.com/tokens",
"body": {
"client_id": "<oauth client id>",
"client_secret": "<oauth client secret>"
}
},
"custom_headers": {
"x-webhook-source": "sparkpost"
},
"match": {
"protocol": "SMTP",
"domain": "email.example.com"
}
}
]
}
List all your relay webhooks.