Edit Monitor

To update an existing monitor, send a PATCH request to /devices/{id} with a JSON body containing the parameters you want to change. You can:

See Monitor Data Fields for all parameters that can be updated.

Note: The operation supports all monitor types except Perfecto.

Syntax

Request URL

PATCH https://www.alertsite.com/alertsite-restapi/devices/{id}

where {id} is the monitor ID.

Authentication

This operation requires authentication. The authenticating user’s role must allow the user to edit monitors.

Request Body

The request body should specify the field name/value pairs you want to update, formatted as a JSON object. For a list of supported data fields, see Monitor Data Fields. Below are some examples.

Enable a monitor:

{
  "enabled": "y"
}

Change the monitor locations to Fort Lauderdale (10), Atlanta (20) and Fremont (30), with Fort Lauderdale as the primary location:

{
  "home_location": 10,
  "locations": [
    { "id" : 10 },
    { "id" : 20 },
    { "id" : 30 }
  ]
}

Change the interval:

{
  "interval": 15
}

Change the interval for a monitor that uses full page monitoring:

{
  "interval": 15,
  "interval_fullpage": 15
}

To replace the DéjàClick script, Selenium script or SoapUI project used by the monitor, include the file contents in the script field, encoded as explained in Add Monitor. If uploading large files, make sure your client timeout is sufficient for the upload to complete.

Response Body

Successful response contains status 0:

{
  "metadata": {
    "login": "demo@example.com",
    "session": "ef770427109e343e",
    "status": "0",
    "message": "No errors.",
  }
}

Error response contains a non-zero status:

{
  "metadata": {
    "login": "demo@example.com",
    "session": "ef770427109e343e",
    "status": "65",
    "message": "Invalid device.",
  }
}

Code Examples

cURL

These commands disable monitor 1234 using different authentication types.

Windows

Note: New lines are added for readability; the actual command should be one continuous line.

Using the login and session ID:

curl -X PATCH "https://www.alertsite.com/alertsite-restapi/devices/1234?login=demo%40example.com&session=SESSION_ID"
  -H "Content-Type: application/json"
  -d "{\"enabled\": \"n\"}"

Using the Authorization header with a bearer token:

curl -X PATCH https://www.alertsite.com/alertsite-restapi/devices/1234
  -H "Content-Type: application/json"
  -H "Authorization: Bearer BEARER_TOKEN"
  -d "{\"enabled\": \"n\"}"

*nix, OS X

Using the login and session ID:

curl -X PATCH "https://www.alertsite.com/alertsite-restapi/devices/1234?login=demo%40example.com&session=SESSION_ID" \
  -H "Content-Type: application/json" \
  -d '{"enabled": "n"}'

Using the Authorization header with a bearer token:

curl -X PATCH https://www.alertsite.com/alertsite-restapi/devices/1234 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer BEARER_TOKEN" \
  -d '{"enabled": "n"}'

Python

This example changes locations for monitor 1234.

import requests  # Requests library - http://docs.python-requests.org
import base64
import json

baseUrl = 'https://www.alertsite.com/alertsite-restapi'
login = 'demo@example.com'  # Replace with your AlertSite login email
password = 'pa55w0rd'       # Replace with your AlertSite password
monitorId = 332522
locations = {
   'home_location': 10,
   'locations': [
      {'id': 10},  # Fort Lauderdale, FL
      {'id': 20},  # Atlanta, GA
      {'id': 72}   # Boston, Massachusetts
   ]
}

# 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.6:
token = base64.b64encode((login + ':' + session).encode('ascii')).decode('ascii')

# Change monitor locations
url = baseUrl + '/devices/' + str(monitorId)
headers = {
   'Content-Type': 'application/json',
   'Authorization': 'Bearer ' + token
}
r = requests.patch(url, data=json.dumps(locations), headers=headers)

result = r.json()['metadata']
if int(result['status']) == 0:
   print('Monitor locations have been updated.')
else:
   print('Error {status}: {message}'.format(**result))

See Also

© 2017 SmartBear Software. All rights reserved.      Terms of Use · Privacy Policy