To delete a monitor, send a DELETE request to /devices/{id}
, where {id}
is the monitor ID.
Syntax
Request URL
DELETE https://www.alertsite.com/alertsite-restapi/devices/{id}
Authentication
This operation requires authentication. The authenticating user’s role must allow the user to delete monitors.
Request Body
None.
Response Body
Successful response contains status
0:
{
"metadata": {
"login": "[email protected]",
"session": "ef770427109e343e",
"status": "0",
"message": "No errors."
}
}
Error response contains a non-zero status
:
{
"metadata": {
"login": "[email protected]",
"session": "ef770427109e343e",
"status": "65",
"message": "Invalid device.",
}
}
Code Examples
cURL
These commands delete monitor 1234 using different authentication types.
Using the session ID:
curl -X DELETE "https://www.alertsite.com/alertsite-restapi/devices/1234?login=demo%40example.com&session=SESSION_ID"
Using the Authorization header with a bearer token:
curl -X DELETE -H "Authorization: Bearer BEARER_TOKEN" https://www.alertsite.com/alertsite-restapi/devices/1234
Python
This code deletes monitor with ID 1234.
Python
import requests # Requests library – http://docs.python-requests.org
import json
import base64
baseUrl = 'https://www.alertsite.com/alertsite-restapi'
login = '[email protected]' # Replace with your AlertSite login email
password = 'pa55w0rd' # Replace with your AlertSite password
monitorId = 1234 # ID of the monitor to delete
# Log in
payload = {'login': login, 'password': password}
r = requests.post(baseUrl + '/login', data=json.dumps(payload), headers={'Content-Type': 'application/json'})
session = r.json()['metadata']['session']
# Generate the bearer token to authenticate subsequent requests
# For Python 2.4-2.x:
# token = base64.b64encode(login + ':' + session)
# For Python 3.x:
token = base64.b64encode((login + ':' + session).encode('ascii')).decode('ascii')
# Delete the monitor
r = requests.delete(baseUrl + '/devices/' + str(monitorId), headers={'Authorization': 'Bearer ' + token})
result = r.json()['metadata']
if int(result['status']) == 0:
print('Monitor {} has been deleted.'.format(monitorId))
else:
print('Error {status}: {message}'.format(**result))