To create a service-level agreement (SLA) for a monitor, send a POST request to /slas, with a JSON body containing the monitor ID and the SLA configuration. The specified monitor must not have an already existing SLA, otherwise, the request will fail.
Request URL
POST https://api.alertsite.com/api/v3/slas
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 SLA configuration. The required fields are:
-
monitor_id– the monitor for which this SLA is created. This monitor must not have an already existing SLA. -
name, must be non-empty. -
the
availabilitygoal as a percentage, must be greater than 0 and less than or equal to 100, with up to three decimal places. -
the
response_timegoal, 0…300 seconds, with up to two decimal places. -
use_fullpage_time, only required for full-page monitors. Ignored otherwise.Tip: To check if a monitor is a full-page monitor, use the Get Monitors operation of AlertSite JSON API and check if interval_fullpageis present and different from -1. -
the
uptimegoal as a percentage, must be greater than 0 and less than or equal to 100, with up to three decimal places. Only required for monitors with the SLA (MultiPOP) monitoring mode; ignored otherwise.Tip: To find out a monitor’s Monitoring Mode, use the Get Monitors operation of AlertSite JSON API and examine the modefield.
For a list and descriptions of all available SLA data fields, see SLA Object.
By default, new SLAs are always in effect 24×7, but you can specify custom operating_periods and exclusions.
If SLA description is not specified, it will be copied from the monitor name.
Examples
Response body
On success, the operation returns HTTP status 200 with the ID of the created SLA:
{
"id": "1234"
}
Error responses have a non-200 status code and contain the errors list, such as:
{
"errors": [
{
"code": 400,
"message": "invalid_request - User authentication failed."
}
]
}
Try it out
Click here to test this operation in AlertSite’s interactive API console.
Code examples
This code creates an SLA for monitor 123456 with the availability goal of 95% and the response time goal of 2 seconds:
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
sla = {
'name': 'Home page SLA',
'monitor_id': 146854,
'availability': 95,
'response_time': 2,
'use_fullpage_time': false
}
# 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']
# Create an SLA
headers = {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
}
r = requests.post(baseUrl + '/slas', data=json.dumps(sla), headers=headers)
result = r.json()
if r.status_code == requests.codes.ok:
print('Successfully created an SLA. ID: ', result['id'])
else:
print('Could not create an SLA. The following errors occurred:', *result['errors'], sep='\n')

Minimal example