API checks
Run up to 5 HTTP requests in order, pass values from one response to the next, and get alerted when any step fails.
Some things can't be tested with one request. To check that users can log in and load their account, you need to log in first, take the token from the response, and use it in the next request. An API check does exactly that.
How it works
- An API check has 1 to 5 steps. Opush runs them in order on each check.
- Each step is one HTTP request with its own checks.
- A step can save values from its JSON response. Later steps use them with
{{name}}. - If any step fails, Opush stops there. The check counts as failed.
- The response time is the total for all steps.
API checks follow the same rules as other monitors: two failures in a row plus a second-location check before they're down. See Monitoring.
Add an API check
In the app, open Following, tap Add, choose Monitor, then Website, and pick API check. In the web console, go to Monitors, click Add monitor, and choose API check.
Step settings
Prop
Type
Each request waits up to 10 seconds. Redirects work like on website monitors: followed, unless you expect a 3xx status.
Save and reuse values
Give each value a name and a path into the JSON response.
| Response | Path | Value |
|---|---|---|
{"data":{"token":"abc"}} | data.token | abc |
{"items":[{"id":42}]} | items[0].id or items.0.id | 42 |
{"ok":true} | ok | true |
- Paths use dots for keys and
[n](or.n) for list items. A leading$.is allowed. - The value must be text, a number, or
true/false. An object, a list, or an empty value doesn't count. - Use short names with lowercase letters and digits, like
tokenoruserid. These work everywhere, including the iPhone app.
Write {{name}} in a later step's URL, header values, or body. Opush replaces it with the saved value.
If the response isn't JSON, or a path finds nothing, the step fails with Couldn't read the JSON value.
Example: log in, then load the account
Step 1: log in
| Setting | Value |
|---|---|
| Method | POST |
| URL | https://api.example.com/login |
| Headers | Content-Type: application/json |
| Body | {"email":"monitor@example.com","password":"…"} |
| Expected status | 200 |
| Save values | token = data.token |
Step 2: load the account
| Setting | Value |
|---|---|
| Method | GET |
| URL | https://api.example.com/me |
| Headers | Authorization: Bearer {{token}} |
| Expected status | 200 |
| Must contain | monitor@example.com |
Use a test account
Request bodies are stored as you type them and aren't hidden. Create a separate account with no real data or permissions for monitoring.
Example: a value in the URL
This checks that the latest release of a GitHub repo can be loaded:
| Step | URL | Save values |
|---|---|---|
| 1 | https://api.github.com/repos/OWNER/REPO | name = full_name |
| 2 | https://api.github.com/repos/{{name}}/releases/latest | — |
The same check as JSON
If you work with the API, steps look like this:
{
"type": "api",
"name": "Login flow",
"interval": 5,
"steps": [
{
"method": "POST",
"url": "https://api.example.com/login",
"headers": [{ "name": "Content-Type", "value": "application/json" }],
"body": "{\"email\":\"monitor@example.com\",\"password\":\"…\"}",
"expect_status": "200",
"extract": { "token": "data.token" }
},
{
"url": "https://api.example.com/me",
"headers": [{ "name": "Authorization", "value": "Bearer {{token}}" }],
"expect_status": "200",
"contains": "monitor@example.com"
}
]
}When a step fails
The push says which step failed and why:
Login flow
Down
Step 2 · HTTP 401 · confirmed from Western EuropeIn the app and the web console, the monitor shows the failed step too.
Edit steps
You can add, remove, and change steps anytime. Saving replaces the whole list of steps. API checks don't get domain and certificate expiry reminders. Add a website monitor for that.