Webhook is a mechanism designed to notify system users about events. Events that the Webhook can notify about:
- a change of the email status (sent, delivered, rejected, read, the recipient followed the link);
- the contact has unsubscribed from the list/subscribed to another list;
- a change in the campaign status;
- a change in the user data;
- adding the verified return address;
- a change in the account status;
- adding a new user (for resellers).
The Webhook is used to track changes in the email status in real time.
Webhook operates as follows: when an event occurs, the previously installed handler sends JSON to the URL that was indicated for this Webhook. Standard ports are used: port 80 for HTTP and port 443 for HTTPS. To install Webhook on the URL with the specified port, you can send the URL in the form: http://11.111.111.11:80
If the URL to which the Webhook is sent is unavailable (the HTTP 200 OK does not respond, the timeout is 3 seconds), attempts to send the Webhook to this URL, until the expected 200 OK is received, will last for 24 hours with an interval of 10 minutes with the additional retry_count parameter, which will increase by 1 after each Webhook re-sending.
If the Webhook fails to be successfully delivered within 24 hours, the attempts stop, and the Webhook status is changed to stopped. An email is sent to the account about the Webhook deactivation and its last response. To reactivate the stopped Webhook, correct the error, then activate it with the setHook API method with the parameter status="active" or change the status in your Account.
Install handler
setHook — install/replace a notification handler for events of a specific type.
Syntax and URL to call the method |
setHook (hook_url, events, [event_format, max_parallel, single_event, status]) |
https://api.selzy.com/en/api/setHook?api_key=KEY&hook_url=URL&event_format=FORMAT&events[]=EVENT&max_parallel=NUM&single_event=1&status=active |
Arguments | |||||||||||||||||||
api_key* | API access key | ||||||||||||||||||
hook_url * | URL to which a request should be sent when an event occurs. Actually, it is a handler identifier. When you call setHook again with the same hook_url, the handler data will be replaced. | ||||||||||||||||||
event_format | The format in which event data is transferred, a mandatory parameter with three value options:
|
||||||||||||||||||
events* | Associative array listing notifications received by the handler. The following strings can be the array keys:
|
||||||||||||||||||
max_parallel | Optional indication of the maximum number of parallel calls to this handler. The default value is 10. | ||||||||||||||||||
single_event | It obtains the value of 1 or 0. Default value: 0
1 — the Webhook notification does not contain arrays, information will be returned only for one event in one notification; 0 — the Webhook notification returns information in the form of arrays (see example below). |
||||||||||||||||||
status | Handler status. Permitted values:active — the handler is active; disabled — the handler is deactivated. |
Call example
https://api.selzy.com/en/api/setHook?api_key=XXX&hook_url=https%3A%2F%2Fmycompany.com%2Fselzy-hook&event_format=json_post_gzip&events[unsubscribe]=*&events[email_status]=ok_read,ok_link_visited&single_event=1&status=active
Handlers list
listHooks — get the list of all handlers.
Syntax and URL to call the method |
listHooks () |
https://api.selzy.com/en/api/listHooks?api_key=KEY |
Arguments | |
api_key * | API access key. |
Return value |
{ "result": [{ "id":3, "url":"https://site.com/selzy-hook", "event_format":"json_post_gzip", "max_parallel":1, "single_event":0, "events": { "subscribe": ["1","2","3"] }, "status": "active" }] } |
Remove handler
RemoveHook — remove the notification handler.
Syntax and URL to call the method |
removeHook (hook_url) |
https://api.selzy.com/en/api/removeHook?api_key=KEY&hook_url=URL |
Arguments | |
api_key * | API access key. |
hook_url* | URL-identifier of the removed handler. |
Webhook example in the JSON format
Example of the webhook sent
{ "auth":"6931402abc4b2a76b9719d911017c592", "num":"12", "events_by_user": [ { "login":"user_zz", "Events": [ { "event_name":"email_status", "event_time":"2015-04-24 15:18:34", "event_data": { "email":"[email protected]", "campaign_id":"124345", "status":"ok_read", "status_group":"success_group", "delivery_info": { "user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36", "ip":"111.111.111" } } }, { "event_name":"email_status", "event_time":"2015-04-24 15:18:36", "event_data": { "email":"[email protected]", "email_id":"346134", "status":"ok_link_visited", "status_group":"success_group", "delivery_info": { "user_agent":"Mozilla/5.0 (X11; Linux x86_64)", "ip":"111.111.111" } } }, { "event_name":"unsubscribe", "event_time":"2015-04-24 15:18:58", "event_data": { "email":"[email protected]", "campaign_id":"87434", "list_id":"3346", "Just_unsubscribed_list_ids": [ "3346", "7473" ], "Just_subscribed_list_ids": [ "9745" ] } } ] } ] }
Description of notification parameters (for single_event = 0)
Notifications in the json_post and json_post_gzip formats are sent in the form of a POST request to the notification URL without additional arguments with Content-Type=application/json (and for json_post_gzip with Content-Encoding: gzip). If json_post_gzip is selected, it is necessary to decompress the GZIP object before reading JSON. The JSON object is transferred in the request body without setting any variables to read the data. For example, you can use the commands on PHP: - gzdecode ($ postData); — for GZIP decompression - file_get_contents ('php: // input'); — for reading JSON.
The notification data is a JSON object with the following fields:
An array of JSON objects, each element of which corresponds to one user. Only resellers may have more than one element in this array — resellers can receive notifications of events from several of their users in one call, in other cases this array consists of one element.
Parameter |
Description |
||||||
auth | MD5 hash of the message string body, in which the auth value is replaced with the api_key of the user whose handler is called. Using this, the notification recipient can both authenticate and verify the integrity of the notification.
To generate auth, you need to form the entire body of the notification in JSON, substitute the auth value of the user's api_key value, and calculate the md5 of the body. Then replace the api_key in the message with the resulting md5 recorded in hexadecimal form in lowercase. To test auth, you need to replace its value with api_key, also calculate the md5 of the notification body, and compare it with the auth value received in the initial notification body. |
||||||
num | URL to which a request should be sent when an event occurs. Actually, it is a handler identifier. When you call setHook again with the same hook_url, the handler data will be replaced. | ||||||
events_by_user | An array of JSON objects, each element of which corresponds to one user. Only resellers may have more than one element in this array — resellers can receive notifications of events from several of their users in one call, in other cases this array consists of one element. | ||||||
login | Login of the user, the event notification of whose we transfer in the relevant element of the array events_by_user. | ||||||
events | An array of the user events with the above login, each array element has the following fields:
|
Event_data format | Description |
email_status |
|
unsubscribe |
|
campaign_status |
|
email_check | Email — email, the right to use which as a return address is confirmed by the user. |
user_payment |
|
user_info |
|
Managing Webhooks from the Account
In your Account, click on your email in the top right-hand side corner and choose Settings.
In the toolbar on the left, select the Webhook section.
Here you will find:
- The Webhook ID.
- The URL with the Webhook.
- Maximum number of parallel calls.
- The events that your Webhook notifies about.
- The Webhook status — active, disabled, or stopped.
- The button to remove the Webhook.
- The history of errors, if any.
If you need to disable the active Webhook, click on the Active button.
To activate the disabled Webhook, click on the Disabled button.
If the Webhook is stopped due to some errors, you can activate it by clicking on the Stopped button.
If there were any errors when the Webhooks were sent to your URL, click on the Error History option to analyze them.