Event Destinations API
- Table of Contents
- Overview
- Attributes
- Get a List of Event Destinations
- Get Details on a Single Event Destination
- Create an Event Destination
- Update an Event Destination
- Delete an Event Destination
Overview
The Event Destinations API manages the event delivery destinations that the “Event Destinations”
page of the Engine UI edits. Each Event Destination is an HTTP destination of the
Event Processor that is configured in
the database instead of in greenarrow.conf. Its
format is json, form or compat_mg
(Mailgun-Compatible Webhooks).
The Event Destinations run beside the event_delivery_destination blocks of
greenarrow.conf. In the configuration, GreenArrow names each Event Destination
ui-destination-{id}, for example ui-destination-12. The config_name attribute gives this
name. It shows in greenarrow events status and in the Event Processor logs. greenarrow.conf
cannot use a name that starts with ui-destination-.
Applying Changes
You do not have to run greenarrow config reload after a change. The
Event Processor reads the enabled Event
Destinations each second, and adds them to its running configuration. Thus a change applies
within about a second. In a cluster, each MTA and event processor instance pulls the Event
Destinations from the shared database every 10 seconds, and its Event Processor then applies them.
The Event Processor checks each enabled Event Destination with the same rules as an
event_delivery_destination block of greenarrow.conf. The API checks most of these rules
when you save, but the Event Processor can still refuse an Event Destination that the API saved.
The error_text attribute gives the error. When
the Event Destination loads, error_text becomes null. A save that changes an attribute other
than name sets error_text to null. If the changed Event Destination does not load, the Event
Processor sets error_text again.
While an Event Destination fails, the Event Processor keeps the settings that it last loaded for
it, and GreenArrow keeps queuing its events. If the Event Processor restarts while an Event
Destination fails, that Event Destination delivers no events until you correct it. GreenArrow
keeps the queued events of that Event Destination. An Event Destination that fails does not stop
the other Event Destinations or a greenarrow config reload.
In a cluster, each MTA and event processor instance writes its own error_text. The leader does
not run the Event Processor, so the API on the leader does not give the errors of the other
instances. An error on an instance shows in the Event Processor log of that instance.
Disabling and Deleting
When you disable an Event Destination (set enabled to false) or delete it, GreenArrow stops
queuing events for it. GreenArrow removes the events in its queue one hour later. A disabled Event
Destination keeps its settings. If you enable it again within that hour, it delivers the events
that are still in its queue. GreenArrow does not queue the events that occur while the Event
Destination is disabled.
Permissions
The API permission of the Engine User (permissions.api in the
Engine Users API) controls access. A user with the
read-only API permission can only get Event Destinations. An
API key has full access.
Attributes
The following attributes are defined for Event Destinations. A null value gives the default of
the greenarrow.conf directive that is shown in parentheses in the description of the attribute.
|
event_ hash /required
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A compat_mg Event Destination also needs the global log_header directive of
greenarrow.conf to log the From, To and Subject headers. The API refuses to create a
compat_mg Event Destination, or to change the format of an Event Destination to compat_mg, if
these headers are not logged. The API checks the configuration of the last
greenarrow config reload. After you add them to greenarrow.conf, run greenarrow config reload
before you save the Event Destination. If greenarrow.conf stops logging these headers later, the
Event Destination continues to deliver, but its webhooks do not include the headers that are not
logged. The Engine UI shows a warning for such an Event Destination.
The API does not support the other event_delivery_destination directives, such as event_delivery_filter_mail_class or event_delivery_client_certificate_file. To use them, configure the destination in greenarrow.conf.
Get a List of Event Destinations
GET /ga/api/v3/eng/event_destinations
Parameters
The following parameters are valid for the above endpoint.
|
page
integer /optional |
The page number from which to retrieve. Page numbering starts at |
|
per_ integer /optional |
The number of records to return on each page. The default is |
|
page_ string /optional |
The |
|
name
string /optional |
Give only the Event Destination that has this name. The comparison ignores case. |
Examples:
GET /ga/api/v3/eng/event_destinations?page={page}
GET /ga/api/v3/eng/event_destinations?page={page}&per_page={per_page}
GET /ga/api/v3/eng/event_destinations?page_token={page_token}
GET /ga/api/v3/eng/event_destinations?name={name}
Response
The response will contain a list of Event Destinations, in the order of their id, in the
following format.
|
event_ array of hashes
|
|||||||||||||
|
pagination
hash
|
|||||||||||||
Example 1: Get the First Page of Event Destinations
GET /ga/api/v3/eng/event_destinations
HTTP/1.1 200 OK
{
"success": true,
"data": {
"event_destinations": [
{
"id": 12,
"name": "Webhooks",
"config_name": "ui-destination-12",
"enabled": true,
"format": "json",
"url": "https://example.com/webhooks"
},
{
"id": 13,
"name": "Mailgun",
"config_name": "ui-destination-13",
"enabled": false,
"format": "compat_mg",
"url": "https://api.example.com/webhooks/mailgun"
},
{
"id": 14,
"name": "Archive",
"config_name": "ui-destination-14",
"enabled": true,
"format": "form",
"url": "https://archive.example.com/events"
}
],
"pagination": {
"page": 0,
"per_page": 100,
"num_pages": 1,
"num_records": 3,
"next_page_token": null
}
},
"error_code": null,
"error_messages": null
}
Example 2: Get a Specific Page of Event Destinations with Per-Page Limits
GET /ga/api/v3/eng/event_destinations?page=1&per_page=2
HTTP/1.1 200 OK
{
"success": true,
"data": {
"event_destinations": [
{
"id": 14,
"name": "Archive",
"config_name": "ui-destination-14",
"enabled": true,
"format": "form",
"url": "https://archive.example.com/events"
}
],
"pagination": {
"page": 1,
"per_page": 2,
"num_pages": 2,
"num_records": 3,
"next_page_token": null
}
},
"error_code": null,
"error_messages": null
}
Example 3: Find an Event Destination by Name
GET /ga/api/v3/eng/event_destinations?name=mailgun
HTTP/1.1 200 OK
{
"success": true,
"data": {
"event_destinations": [
{
"id": 13,
"name": "Mailgun",
"config_name": "ui-destination-13",
"enabled": false,
"format": "compat_mg",
"url": "https://api.example.com/webhooks/mailgun"
}
],
"pagination": {
"page": 0,
"per_page": 100,
"num_pages": 1,
"num_records": 1,
"next_page_token": null
}
},
"error_code": null,
"error_messages": null
}
Get Details on a Single Event Destination
GET /ga/api/v3/eng/event_destinations/{id}
Response
The response will contain details on the requested record:
|
event_ hash |
The attributes for this hash are defined in the Attributes section of this document. |
If there is no Event Destination with this id, the error_code is not_found.
Example
GET /ga/api/v3/eng/event_destinations/12
HTTP/1.1 200 OK
{
"success": true,
"data": {
"event_destination": {
"id": 12,
"name": "Webhooks",
"config_name": "ui-destination-12",
"enabled": true,
"format": "json",
"url": "https://example.com/webhooks",
"timeout_seconds": null,
"disable_batching": null,
"http_keepalive": null,
"http_user_agent": null,
"max_batch_size": null,
"max_concurrent_connections": null,
"verify_peer": null,
"event_types": [
"delivery_attempt",
"engine_click"
],
"delivery_attempts": {
"status_success": true,
"status_deferral": false,
"status_failure": true,
"status_failure_toolong": true,
"status_connmaxout": false,
"include_first_attempt_regardless_of_status": true,
"include_local_channel": false
},
"anonymize_localparts": null,
"anonymize_clicktrackingid": null,
"compat_mg": {
"signing_key_is_set": false,
"webhooks": []
},
"error_text": null
}
},
"error_code": null,
"error_messages": null
}
Create an Event Destination
POST /ga/api/v3/eng/event_destinations
Payload
|
event_ hash /required |
The content of this hash is described in the Attributes section of this page. The data may contain a mixture of required and optional fields. Do not specify read-only fields. |
Response
The response will include an event_destination key containing the full Event Destination
record as defined in the Event Destination Attributes.
Example 1: Create a Mailgun-Compatible Event Destination
For this example, the global log_header directive must log the From, To and Subject
headers. See the note after Attributes.
POST /ga/api/v3/eng/event_destinations
{
"event_destination": {
"name": "Mailgun",
"format": "compat_mg",
"url": "https://api.example.com/webhooks/mailgun",
"compat_mg": {
"signing_key": "key-3ax6xnjp29jd6fds4gc373sgvjxteol0",
"webhooks": [
"permanent_fail",
"complained"
]
}
}
}
HTTP/1.1 200 OK
{
"success": true,
"data": {
"event_destination": {
"id": 13,
"name": "Mailgun",
"config_name": "ui-destination-13",
"enabled": true,
"format": "compat_mg",
"url": "https://api.example.com/webhooks/mailgun",
"timeout_seconds": null,
"disable_batching": null,
"http_keepalive": null,
"http_user_agent": null,
"max_batch_size": null,
"max_concurrent_connections": null,
"verify_peer": null,
"event_types": [],
"delivery_attempts": {
"status_success": true,
"status_deferral": false,
"status_failure": true,
"status_failure_toolong": true,
"status_connmaxout": false,
"include_first_attempt_regardless_of_status": true,
"include_local_channel": false
},
"anonymize_localparts": null,
"anonymize_clicktrackingid": null,
"compat_mg": {
"signing_key_is_set": true,
"webhooks": [
"permanent_fail",
"complained"
]
},
"error_text": null
}
},
"error_code": null,
"error_messages": null
}
Example 2: Validation Errors
In this example, the Event Destination “Webhooks” already exists.
POST /ga/api/v3/eng/event_destinations
{
"event_destination": {
"name": "WEBHOOKS",
"url": "ftp://example.com",
"max_batch_size": 0,
"event_types": [
"bogus"
]
}
}
HTTP/1.1 200 OK
{
"success": false,
"data": null,
"error_code": "validation_failed",
"error_messages": [
"event_destination.name: has already been taken",
"event_destination.url: must be a URL that starts with http:// or https:// and has a host name",
"event_destination.max_batch_size: must be greater than or equal to 1",
"event_destination.event_types: contains an unknown event type: bogus"
]
}
Update an Event Destination
PUT /ga/api/v3/eng/event_destinations/{id}
An update changes only the attributes that the request names.
For an attribute whose default is null, a null value clears it, so the default of its
greenarrow.conf directive applies. name, enabled, format, url and the delivery_attempts
values cannot be null. A null or blank compat_mg.signing_key keeps the current key.
Payload
|
event_ hash /required |
The content of this hash is described in the Attributes section of this page. The data may contain a mixture of required and optional fields. Do not specify read-only fields. |
Response
The response will include an event_destination key containing the full Event Destination
record as defined in the Event Destination Attributes. An update that changes an
attribute other than name sets error_text to null. See Applying Changes.
If there is no Event Destination with this id, the error_code is not_found.
Example 1: Change the Timeout
PUT /ga/api/v3/eng/event_destinations/12
{
"event_destination": {
"timeout_seconds": 15
}
}
HTTP/1.1 200 OK
{
"success": true,
"data": {
"event_destination": {
"id": 12,
"name": "Webhooks",
"config_name": "ui-destination-12",
"enabled": true,
"format": "json",
"url": "https://example.com/webhooks",
"timeout_seconds": 15,
"disable_batching": null,
"http_keepalive": null,
"http_user_agent": null,
"max_batch_size": null,
"max_concurrent_connections": null,
"verify_peer": null,
"event_types": [
"delivery_attempt",
"engine_click"
],
"delivery_attempts": {
"status_success": true,
"status_deferral": false,
"status_failure": true,
"status_failure_toolong": true,
"status_connmaxout": false,
"include_first_attempt_regardless_of_status": true,
"include_local_channel": false
},
"anonymize_localparts": null,
"anonymize_clicktrackingid": null,
"compat_mg": {
"signing_key_is_set": false,
"webhooks": []
},
"error_text": null
}
},
"error_code": null,
"error_messages": null
}
Example 2: Change the Name
PUT /ga/api/v3/eng/event_destinations/12
{
"event_destination": {
"name": "Order Webhooks"
}
}
The response is the full Event Destination, with name set to Order Webhooks.
Delete an Event Destination
DELETE /ga/api/v3/eng/event_destinations/{id}
See Disabling and Deleting for what happens to the queued events.
Response
The response is a standard success or error response. If there is no Event Destination with this
id, the error_code is not_found.
Example
DELETE /ga/api/v3/eng/event_destinations/13
HTTP/1.1 200 OK
{
"success": true,
"data": {
},
"error_code": null,
"error_messages": null
}
