Skip to content

Add Alert

Request

Use this endpoint to add new alert settings record. This service facilitates notifications (Webhook, Slack, or Email) for both Mailgun Optimize and Send Alert threshold breaches.

Webhooks

This section covers details around consuming alerts via webhooks. If you are familiar with Mailgun Send webhooks (which provide status updates on individual email deliveries), there is a lot of overlapping similarity, however, there are also a few minor nuances to account for.

Securing Webhooks

HMAC is used to verify the integrity as well as the authenticity of received webhooks. To verify the origin of a webhook:

  1. Encode the webhook’s entire POST request body with the HMAC algorithm (using your webhook signing key and SHA256 digest mode)
  2. Compare the resulting hexdigest to the signature provided in the POST request’s X-Sign header.

NOTE: If you’re consuming Mailgun Send webhooks, please note that your Mailgun Send webhook signing key differs from your Alerts webhook signing key. Your Alerts webhook signing keys, used for both Optimize and Send Alert products, are available within the Mailgun Alerts UI.

Webhook URL Validation

When adding or updating a webhook URL for alerts, we will ensure the endpoint is reachable by sending a GET request to the provided URL. If a 200 response is not returned from your endpoint, the request will be rejected and your alert setting will not be saved. We intentionally chose to send a GET request instead of a POST when validating URLs so that your webhook endpoint does not have to account for test requests.

Additionally, when a POST request is sent to your webhook URL, if a 2xx is not returned, we will attempt retries via an exponential backoff strategy for up to ~8 hours. If the max retry count is reached, the alert will be disabled and the related alert settings record’s disabled_at field will be populated.

Security
basicAuth
Bodyapplication/jsonrequired
event_typestringrequired

The type of event for which you would like to receive alerts.

channelstring(github.com-mailgun-alerts-channels-Channel)required

The delivery method for the alert.

Enum ValueDescription
email

email

webhook

webhook

slack

Slack

settingsobject(github.com-mailgun-alerts-internal-settings-ChannelSettings)required

The details pertaining to the specified channel. Please note that the contents of this object differ per channel type.

curl -i -X POST \
  -u '<username>:<password>' \
  https://api.mailgun.net/v1/alerts/settings/events \
  -H 'Content-Type: application/json' \
  -d '{
    "event_type": "ip_listed",
    "channel": "webhook",
    "settings": {
      "url": "https://yourwebhookurl.com"
    }
  }'

Responses

A 200 response

Bodyapplication/json
idstring, (uuid)

The unique identifier for the alert settings record.

event_typestringrequired

The event type that is alerted on. Check GET /v1/alerts/events for possible values.

channelstring(github.com-mailgun-alerts-channels-Channel)required

The delivery channel for the alert.

Enum ValueDescription
email

email

webhook

webhook

slack

Slack

settingsobject(github.com-mailgun-alerts-internal-settings-ChannelSettings)required

This object contains channel-specific settings.

disabled_atstring or null, (date-time)

When present, the timestamp indicating when a webhook endpoint was disabled.

Response
{ "id": "00000000-0000-0000-0000-000000000000", "event_type": "ip_listed", "channel": "webhook", "settings": { "url": "https://yourwebhookurl.com" } }