Adding a New Webhook Destination
- Visit https://app.courier.com/settings/general
- Click the ”+ Outbound Webhook” button
- Enter the new webhook destination information (this should accept a
POSTrequest)
Handling Requests from Courier
Read the Event Data
Courier sends the event data in the request body. Each event is structured as an object with atype property and related resource data nested under the data property.
Handle the Event
Courier currently supports the following event types:message:updatednotification:submittednotification:submission_cancelednotification:publishedaudiences:updatedaudiences:user:matchedaudiences:user:unmatchedaudiences:calculated
type property in the received payload. Additional event types may be added in the future.
Return a 200 Response
Send a successful 200 response to Courier as quickly as possible. Write any long-running processes as code that can run asynchronously outside the webhook endpoint.Verifying Signatures
Verify the events that Courier sends to your webhook endpoints. Courier can optionally sign the webhook events it sends to your endpoints by including a signature in each event’scourier-signature header. This allows you to verify that the events were sent by Courier, not by a third party.
Step 1: Extract the Timestamp and Signature from the Header
Split the header using the, character as the separator to get a list of elements. Then split each element using the = character as the separator to get a prefix and value pair.
The value for the prefix t corresponds to the timestamp, and signature corresponds to the signature.
Before you can verify signatures, you need to retrieve your endpoint’s secret from your Webhooks settings by clicking on a webhook configuration.
Step 2: Prepare the signed_payload String
The signed_payload string is created by concatenating:
- The timestamp (as a string)
- The actual JSON payload (i.e., the request body)
Step 3: Determine the Expected Signature
Compute an HMAC with the SHA256 hash function. Use the Courier webhook secret as the key and the payload string as the message.Step 4: Compare the Signatures
Compare the signature (or signatures) in the header to the expected signature. For an equality match, compute the difference between the current timestamp and the received timestamp, then decide if the difference is within your tolerance. To protect against timing attacks, use constant-time string comparison to compare the expected signature to each of the received signatures.Event Data
message:updated
Thedata property in the webhook response payload for the message:updated event is identical to the information returned from the GET /message/:message_id endpoint.
For example, when an email is sent, it goes from ENQUEUED → SENT → DELIVERED → OPENED.
Here’s a rundown of how the payloads would look for each event:
Example Payload for an ENQUEUED Event
For the notification template submission workflow, Courier emits
notification:submitted, notification:submission_canceled, and notification:published events.