Webhooks

With Exponea webhooks you can notify arbitrary HTTP-based service from a scenario with custom data. Webhook is a simple HTTP GET or POST request sent from Exponea web application to a custom endpoint.

How to setup a webhook

Webhook is one of action nodes in Exponea scenario editor. From action nodes drag&drop webhook node to board and connect it with any available trigger. Double-click on webhook node to enter endpoint URL and format of the request.
Screen Shot 2016-05-04 at 12.55.30
There are two modes how Exponea can process webhooks. Bulk and per customer. In bulk mode all customer data are sent in one request (max. bulk size is 1000 customers). Per customer mode generates single request for each customer that enters webhook node in scenario.

Bulk mode

When using bulk mode, up to 1000 customers are sent in one request. Webhooks targeted at more than 1000 customers are split into multiple requests with same custom data and customers array containing up to 1000 customers. Bulk webhooks are sent as POST requests only.
If you use on-event trigger, each webhook will contain all customers that triggered event during period of time.
Webhook edit UI:
Screen Shot 2016-05-04 at 12.05.57

Request format

Bulk request contains two main parts: customers array & data array. The customers array contains a list (array) of all targeted customers. The data array is customisable and contains custom static data specified in the webhook (in JSON format).
Example of event-triggered bulk webhook:

Sample endpoint implementation in PHP

For easier integration of Exponea webhooks into your application, we provide you with the simplest implementation of the endpoint. The following code sample receives and decodes webhook data and responds with properly formatted response.

Per customer mode

Per customer mode generates single request for each customer that enters webhook node in scenario. Per customer mode supports both GET and POST method. In custom data field you can define whole raw body in JSON format. You can use Jinja tags to use dynamic and personalized information:
Screen Shot 2016-05-04 at 13.20.34

Response

Proper response must be sent back to the Exponea web application for webhook to work correctly. In case the endpoint answers in incorrect format or doesn’t answer at all, the webhook tries to send the request again with exponential backoff, in bulk mode at maximum 7 times. Proper answer is a JSON with following structure with HTTP status code 200. If proper answer is received, campaign with attribute ‘sent’ is created. If unsuccessful (for 7 times), event with attribute ‘failed’ is created. In per customer mode the number of tries is set to 3.

Code 200-399 gives successful ‘sent’ status_code attribute. Code 400-499 gives ‘failed’ status_code attribute and sets up message with first 100 signs from raw message. If other, webhook will retries as mentioned above.