Skip to content

API quickstart

This creates one HTTP check through the REST API, tests it from several countries, and reads its results. You need curl, jq and an account.

In the dashboard, open Settings → API tokens → Create token. Give it the scopes checks:read, checks:write, nodes:read and incidents:read, and keep the value in the environment:

Terminal window
export MONITORLY_TOKEN=mly_…
export API=https://app.monitorly.cloud/api/v1

The value is shown once. Never put it in a file you commit (Authentication).

Your workspaces
curl -fsS "$API/workspaces" -H "Authorization: Bearer $MONITORLY_TOKEN" | jq '.[] | {id, name}'
Projects of the first workspace
WORKSPACE=$(curl -fsS "$API/workspaces" -H "Authorization: Bearer $MONITORLY_TOKEN" | jq -r '.[0].id')
curl -fsS "$API/workspaces/$WORKSPACE/projects" -H "Authorization: Bearer $MONITORLY_TOKEN" | jq '.[] | {id, name}'
PROJECT=$(curl -fsS "$API/workspaces/$WORKSPACE/projects" -H "Authorization: Bearer $MONITORLY_TOKEN" | jq -r '.[0].id')

A check runs on the nodes you choose. List them with their location and health, and pick two or more in different countries, so that one failing location cannot open an incident on its own (How DOWN is decided):

Nodes
curl -fsS "$API/workspaces/$WORKSPACE/nodes" -H "Authorization: Bearer $MONITORLY_TOKEN" \
| jq '.[] | {id, name, countryCode, health: .health.status}'
NODES=$(curl -fsS "$API/workspaces/$WORKSPACE/nodes" -H "Authorization: Bearer $MONITORLY_TOKEN" \
| jq -c '[.[] | select(.health.status == "online") | .id][:3]')

A test runs the check once on each of its nodes and saves nothing:

check.json
cat > check.json <<EOF
{
"name": "payments-health",
"intervalSecs": 300,
"nodes": $NODES,
"kind": {
"type": "http",
"method": "GET",
"url": "https://api.acme.io/healthz",
"maxRedirects": 0,
"assertions": [{ "target": "status", "op": "eq", "value": 200 }]
}
}
EOF

Five minutes is an interval every plan allows; the shortest is on Plans and limits.

Start the test, then read its results
TEST=$(jq '{check: .}' check.json | curl -fsS "$API/projects/$PROJECT/check-tests" \
-H "Authorization: Bearer $MONITORLY_TOKEN" -H "Content-Type: application/json" --data @- | jq -r '.id')
sleep 15
curl -fsS "$API/check-tests/$TEST" -H "Authorization: Bearer $MONITORLY_TOKEN" \
| jq '{done, results: [.results[] | {nodeId, status, outcome, statusCode, ms: .timings.totalMs}]}'

done turns true when every node has answered or its deadline passed: the check’s timeout plus 5 seconds.

Create it, safe to retry
CHECK=$(curl -fsS "$API/projects/$PROJECT/checks" \
-H "Authorization: Bearer $MONITORLY_TOKEN" -H "Content-Type: application/json" \
-H "Idempotency-Key: payments-health-1" --data @check.json | jq -r '.check.id')

A retry with the same Idempotency-Key returns the first answer and creates nothing again (Idempotency).

Status, uptime and each location
curl -fsS "$API/checks/$CHECK" -H "Authorization: Bearer $MONITORLY_TOKEN" \
| jq '{status, uptime30dPercent, stations: [.stations[] | {nodeName, outcome, totalMs}]}'
The latest runs
curl -fsS "$API/checks/$CHECK/runs?limit=10" -H "Authorization: Bearer $MONITORLY_TOKEN" \
| jq '.items[] | {slotAt, nodeId, outcome, statusCode, totalMs}'
Incidents of the project
curl -fsS "$API/projects/$PROJECT/incidents?state=open" -H "Authorization: Bearer $MONITORLY_TOKEN" \
| jq '.items[] | {checkName, openedAt, ackedAt}'

status is absent until the check is first evaluated, then PENDING until its first decision. Alerts go to the project’s alert channels: add one with Add an alert channel or in the dashboard (Alert channels).

Errors are application/problem+json. Branch on type, not on the text:

{ "type": "token.scope_missing", "title": "Forbidden", "status": 403, "detail": "this token needs the scope checks:write", "errors": [] }

Field errors point at the field in errors[].pointer, for example /kind/url. Every code is on Errors, and every operation with its parameters, scopes and examples is in the REST reference.