Send a test alert to an arbitrary recipient (not necessarily an existing AlertSite recipient) from the specified AlertSite location.
To test an existing alert recipient, call GET /recipients/{id}
to get the recipient details, then send a test alert using the recipient’s method_id
, recipient
, username
and password
.
Notes:
-
Test alerts can be sent from public AlertSite locations only. The API does not support testing alerts from private locations.
-
This operation uses the default alert templates for the specified alerting method. Keep this in mind when testing recipients that require custom templates, such as Slack and VictorOps recipients for JSON alerts.
Request URL
POST https://api.alertsite.com/api/v3/test-notifiers
Authentication
The request must include the Authorization
header containing a user’s access token:
Authorization: Bearer ACCESS_TOKEN
See Authentication for more information.
Request body
The request body is a JSON object containing the following fields. The minimum required fields are method_id
and recipient
.
Field | Type | Description |
---|---|---|
location_id |
Integer | Optional. The ID of a public AlertSite monitoring location to send the alert from. See here for a list of location IDs. If omitted, the alert will be sent from your account’s primary location configured in the account settings. |
method_id |
Integer |
Required. Alert delivery method:
When testing existing recipients, use the Refer to Alert Delivery Methods for specifics of using various delivery methods. |
recipient |
String | Required. The alert destination, such as an email address, phone number, URL or similar.
When testing existing recipients, use the recipient value returned by GET /recipients or GET /recipients/{id} . To send a test alert to an arbitrary contact, see here for the expected value format for various alert delivery methods. |
username and password |
String | Required for ServiceNow and Splunk alerts, optionally used for JSON alerts. The username and password for authenticating with the recipient . When testing existing recipients, use the username and password values returned by GET /recipients or GET /recipients/{id} . |
Examples
Send a test alert to an email address from the account’s primary location:
{
"method_id": 12,
"recipient": "[email protected]"
}
Send a JSON alert from Atlanta (location ID 20) to the specified URL that is protected with Basic authentication:
{
"location_id": 20,
"method_id": 16,
"recipient": "https://my.server.com/webhooks/alertsite",
"username": "alertsite-integration",
"password": "p@55w0rd"
}
Response body
On success, the operation returns HTTP status 200 OK.
Error responses have an HTTP status code in the 4xx series.
Try it out
Click here to test this operation in AlertSite’s interactive API console.
Code examples
This code sends a test alert to an email address from the account’s primary location.
cURL (Windows)
curl -X POST https://api.alertsite.com/api/v3/test-notifiers
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
-H "Content-Type: application/json"
-d "{\"method_id\": 12, \"recipient\": \"[email protected]\"}"
Note: New lines are added for readability.
The actual command should be one continuous line.
cURL (bash)
curl -X POST https://api.alertsite.com/api/v3/test-notifiers \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"method_id": 12, "recipient": "[email protected]"}'
Python
# Python 3.5+
import requests # Requests library http://docs.python-requests.org
import json
baseUrl = 'https://api.alertsite.com/api/v3'
username = '[email protected]' # Replace with your AlertSite login email
password = 'pa55w0rd' # Replace with your AlertSite password
# Parameters of a test alert
test_alert = {
'method_id': 12,
'recipient': '[email protected]'
}
# Log in
payload = {'username': username, 'password': password}
r = requests.post(baseUrl + '/access-tokens', data=json.dumps(payload), headers={'Content-Type': 'application/json'})
token = r.json()['access_token']
# Send a test alert
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
}
r = requests.post(baseUrl + '/test-notifiers', data=json.dumps(test_alert), headers=headers)
if r.status_code == requests.codes.ok:
print('A test alert has been sent to', test_alert['recipient'])
else:
print('Could not send a test alert. The following errors occurred:', *r.json()['errors'], sep='\n')