Create an API Endpoint Monitor

Last modified on July 26, 2024

With AlertSite Management API, you can create an API endpoint monitor to send one or more HTTP and HTTPS requests to an API and check the response time, status, and response contents.

To create a new API endpoint monitor:

  • Send a POST request to /monitors/website-api with a JSON body containing the monitor configuration to check an HTTP API endpoint.

    -- or --

  • Send a POST request to /monitors/website-ssl-api with a JSON body containing the monitor configuration to check an HTTPS API endpoint.

An API endpoint can be a multi-step monitor which is a mix of HTTP and HTTPS requests. To create such a monitor, send a POST request to either /monitors/website-api or /monitors/website-ssl-api with appropriate configurations.

Request URL

POST https://api.alertsite.com/api/v3/monitors/website-api

POST https://api.alertsite.com/api/v3/monitors/website-ssl-api

Authentication

The request must include the Authorization header containing a user’s access token:

Authorization: Bearer ACCESS_TOKEN

See Authentication for more information.

The authenticating user must have permissions to create monitors.

Request body

The request body is a JSON object containing the monitor configuration parameters (see Monitor Object). The minimum required fields are:

  • billing_plancode

  • name

  • api_steps

{
  "billing_plancode": "UBM - A/A",
  "name": "Sample API Monitor"
}

Here is the example with all supported fields (see Monitor Object for a description of these fields):

{
  "alert_note":"Optional alert note",
  "allow_internal_testing":false,
  "api_steps":[
    {
      "assertions":[
        {
          "comparison":"exists",
          "property":"uuid",
          "source":"JSON Response",
          "value":""
        }
      ],
      "head":{
        "http_basic_auth_password":"",
        "http_basic_auth_username":"",
        "preemptive_authentication":false
      },
      "http_method":"GET",
      "post":null,
      "step_name":"Get UUID",
      "step_number":1,
      "url":"http://httpbin.org/uuid",
      "variables":[
        {
          "name":"uuid",
          "property":"uuid"
        }
      ]
    },
    {
      "assertions":[
        {
          "comparison":"exists",
          "property":"json.uuid",
          "source":"JSON Response",
          "value":""
        }
      ],
      "head":{
        "http_basic_auth_password":"",
        "http_basic_auth_username":"",
        "preemptive_authentication":false
      },
      "http_method":"CUSTOM",
      "post":{
        "http_header_use_custom":true,
        "http_post_data_key_value_pairs":"POST /post HTTP/1.1\nContent-Type: application/json\n\n{\n \"uuid\": \"{{uuid}}\"\n}",
        "http_post_data_raw":true
      },
      "step_name":"Send UUID",
      "step_number":2,
      "url":"https://httpbin.org/post",
      "variables":[]
    }
  ],
  "billing_plancode":"UBM - A/A",
  "capture":{
    "headers":true,
    "images":true,
    "level":"Error Only",
    "mimetype":"image/jpeg",
    "sources":true
  },
  "custom_properties":[
    {
      "id":228,
      "name":"Environment",
      "value":"development",
      "value_id":550
    }
  ],
  "enabled":true,
  "get":{
    "http_302_is_error":false,
    "http_401_is_error":true,
    "interval_fullpage":-1
  },
  "has_active_performance_alerts":false,
  "has_performance_alerts":false,
  "has_sla":false,
  "home_location":1201,
  "id":123456,
  "interval":5,
  "local_validation":false,
  "locations":[
    {
      "id":10,
      "name":"Fort Lauderdale (FL)",
      "region":1
    },
    {
      "id":20,
      "name":"Atalnta (GA)",
      "region":1
    }
  ],
  "mode":"Global Verify",
  "monitor_location_count":1,
  "monitor_uses_own_locations":true,
  "name":"Sample API EndPoint Monitor",
  "note":"Optional monitor note",
  "notify_on_error":true,
  "retry_on_failure":true,
  "rotate_locations":true,
  "sla_id":null,
  "ssl_cert_format":null,
  "ssl_cert_id":null,
  "ssl_cert_name":null,
  "timeout":30,
  "transaction_steps":1,
  "transaction_steps_allowed":50,
  "transaction_trace":false,
  "type":"website-ssl-api",
  "use_client_ssl_cert":false,
  "use_ssl_version":"2"
}

Parameters that are not specified in the request body will take the values specified in AlertSite defaults and your account defaults. For example, if you do not specify locations for the monitor, it will use your account's default monitoring locations.

Response body

On success, the operation returns the ID of the created monitor.

{
  "id": "123456"
}

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

You can test the operations in AlertSite’s interactive API console:

Code example

This code creates a monitor that sends a GET request with a JSON assertion to an API endpoint.

Python

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

monitor_params = {
  'billing_plancode': 'UBM - A/A',
  'name': 'HTTP GET with assertion',
  'api_steps': [
    {
      'assertions': [
        {
          'comparison': 'equals',
          'property': 'arg.status',
          'source': 'JSON Response',
          'value': 'available'
        }
      ],
      'head': {
        'http_basic_auth_password': '',
        'http_basic_auth_username': '',
        'preemptive_authentication': False
      },
      'http_method': 'GET',
      'url': 'https://httpbin.org/get?status=available',
      'step_name': 'Check status',
      'interval': 15,
      'enabled': True
    }
  ]
}

# Login
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 the monitor
headers = {
  'Authorization': 'Bearer ' + token,
  'Content-Type': 'application/json'
}
r = requests.post(baseUrl+'/monitors/website-ssl-api', data=json.dumps(monitor_params), headers=headers)
result = r.json()
if r.status_code == requests.codes.ok:
    monitor_id = result['id']
    print('Successfully created the monitor. ID:{}'.format(monitor_id))
else:
    print('Could not create a monitor. The following error(s) occurred:', *result['errors'], sep='\n')

See Also

Monitor Operations
Edit a Website Monitor
Convert API Endpoint Monitors to SoapUI
Delete Monitor

Highlight search results