When using AlertSite Management API, the first request needs to be an access token request. To get an access token, send a POST request to /access-tokens
with a body containing AlertSite username
and password
in the JSON format (see the syntax below). A successful request returns an access_token
. You need to send this token in the Authorization: Bearer TOKEN
header in subsequent requests.
Access tokens expire after 1 hour, after which the calls to AlertSite Management API will return HTTP status 401 (Unauthorized). In this case, you can get a new access token by calling POST /access-tokens
again.
Request URL
POST https://api.alertsite.com/api/v3/access-tokens
Request body
{
"username": "[email protected]",
"password": "passw0rd"
}
Response body
A successful response has HTTP status 200 OK and contains an access token:
{
"access_token": "695573df9519132454d3f461179aaaf9"
}
You need to send this token in the Authorization: Bearer TOKEN
header in subsequent API calls.
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
cURL (Windows)
curl -X POST https://api.alertsite.com/api/v3/access-tokens
-H "Content-Type: application/json"
-d "{\"username\": \"[email protected]\", \"password\": \"passw0rd\"}"
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/access-tokens \
-H 'Content-Type: application/json' \
-d '{"username": "[email protected]", "password": "passw0rd"}'
Python
import requests # Requests library – http://docs.python-requests.org
import json
username = '[email protected]' # Replace with your AlertSite login email
password = 'pa55w0rd' # Replace with your AlertSite password
payload = {'username': username, 'password': password}
r = requests.post('https://api.alertsite.com/api/v3/access-tokens',
data=json.dumps(payload),
headers={'Content-Type': 'application/json'})
if r.status_code == requests.codes.ok:
token = r.json()['access_token']
print('Access token:', token)
else:
print('Authentication failed:')
for error in r.json()['errors']:
print(*errors, sep='\n')