Automate
REST API quick start
Call the API with curl: list projects, start a test, read its verdict and JUnit file; errors, rate limits, pages, approvals.
Everything you do in Swarmetry, a program can do too, through the REST API: the web app itself uses it. This page takes you through a first session in a terminal, step by step: list your projects, start a load test, read its verdict and get its JUnit file. Then it explains what every program meets: errors, rate limits, pages of a list, and the operations that cost or delete something.
Every operation, with its fields and a curl example, is in the API reference: Help > Developer access > API
reference (/app/developer/api). To gate a CI pipeline on a load test, the ready files of
page 29 do the waiting for you.
Before you start
-
A terminal with
curl. macOS and Linux have both. The commands of this page are written for a Linux or macOS terminal (sh,bashorzsh); on Windows, run them in WSL or Git Bash. -
A token. Create one of these two:
- a personal token, which acts as you: Account > API tokens (
/app/settings/tokens), see API tokens; - a service account token, for a script or a pipeline that does not belong to one person: Administration > Service accounts (page 31).
The secret (it starts with
sw_pat_orsw_sat_) is shown once. Keep it like a password: never in a file of your repository, never in a message. - a personal token, which acts as you: Account > API tokens (
-
The address of your server. The commands below use
https://swarmetry.io.
In your terminal, put the token in a variable. Every command below reads it from there, so it never shows on a command line:
export SWARMETRY_TOKEN='<token>'
Replace <token> with your token and keep the quotes. Do the same with each <...> of the next steps.
1. List your projects
curl -H "Authorization: Bearer $SWARMETRY_TOKEN" https://swarmetry.io/api/v1/projects
The answer is JSON. The server sends it on one line; here it is spread out to be read:
{
"items": [
{
"id": "019a6c1e-3f2b-7d4a-9c8e-5b1f0e2d4a61",
"name": "Shop",
"description": "",
"createdAt": "2026-11-02T09:14:03Z",
"updatedAt": "2026-11-02T09:14:03Z"
}
]
}
Keep the id of the project you want to test:
export PROJECT_ID='<project id>'
2. Find the test to start
A load test starts from a scenario (what the virtual users do) and one of its test configurations (how many virtual users, how long, and the thresholds that decide the verdict). List the scenarios of the project:
curl -H "Authorization: Bearer $SWARMETRY_TOKEN" \
"https://swarmetry.io/api/v1/projects/$PROJECT_ID/scenarios"
Keep the id of the scenario, then list its test configurations:
export SCENARIO_ID='<scenario id>'
curl -H "Authorization: Bearer $SWARMETRY_TOKEN" \
"https://swarmetry.io/api/v1/projects/$PROJECT_ID/scenarios/$SCENARIO_ID/test-configs"
export TEST_CONFIG_ID='<test configuration id>'
A shortcut: open the test configuration in the web app. Its address holds the three ids,
/app/projects/<project>/scenarios/<scenario>/configs/<test configuration>.
3. Start the test
curl -X POST -H "Authorization: Bearer $SWARMETRY_TOKEN" -H "Content-Type: application/json" \
-d "{\"scenarioId\": \"$SCENARIO_ID\", \"testConfigId\": \"$TEST_CONFIG_ID\", \"note\": \"Started from the API\"}" \
"https://swarmetry.io/api/v1/projects/$PROJECT_ID/runs"
The test starts at once. It sends load to your site and uses the quotas of your plan; over the API nothing asks you to confirm it (see Operations that cost or delete). The answer is the new run:
{
"id": "019a6c2f-8e14-7b3c-a5d2-9f0c1e7b6a28",
"number": 12,
"status": "queued",
"scenarioId": "019a6c1f-0a7d-7e52-8b61-2c4d9e3f5a10",
"testConfigId": "019a6c1f-4c90-7f13-9e27-6d8a1b5c3e42",
"note": "Started from the API"
}
The answer has more fields: the API reference lists them under run.start. Keep the id of the run:
export RUN_ID='<run id>'
4. Read its verdict
curl -H "Authorization: Bearer $SWARMETRY_TOKEN" \
"https://swarmetry.io/api/v1/projects/$PROJECT_ID/runs/$RUN_ID"
Run it again every few seconds until status says the test has ended:
status |
Meaning |
|---|---|
queued, preparing, running, stopping |
The test is not over yet |
finished |
The test ran to its end |
aborted |
The test was stopped: by a person, by a threshold that stops on failure, or by a limit |
failed |
The test could not run (errorCode says why) |
In a script, this loop asks every 10 seconds and ends with the test:
while curl -s -H "Authorization: Bearer $SWARMETRY_TOKEN" \
"https://swarmetry.io/api/v1/projects/$PROJECT_ID/runs/$RUN_ID" |
grep -Eq '"status": ?"(queued|preparing|running|stopping)"'; do
sleep 10
done
Then the same command shows the verdict:
{
"id": "019a6c2f-8e14-7b3c-a5d2-9f0c1e7b6a28",
"number": 12,
"status": "finished",
"verdict": "pass",
"verdictReasons": [],
"finishedAt": "2026-11-09T10:42:17Z"
}
verdict |
Meaning |
|---|---|
pass |
Every threshold was judged on complete measurements, and none failed |
fail |
A threshold failed |
inconclusive |
Nothing failed, but measurements were lost or a threshold could not be judged |
| (absent) | No verdict: the test configuration has no threshold, or the test did not run |
verdictReasons says why, as codes with their details (code, params). An inconclusive verdict can still change
during about 90 seconds after the end, when late measurements arrive. The command line waits for all of this for you,
retries when the server is busy and ends with a code per verdict: swarmetry run wait (page 28).
5. Get the JUnit file
curl -H "Authorization: Bearer $SWARMETRY_TOKEN" -o swarmetry-junit.xml \
"https://swarmetry.io/api/v1/projects/$PROJECT_ID/runs/$RUN_ID/export?format=junit"
swarmetry-junit.xml holds one test case for the verdict, one per threshold and one per check. CI tools (GitLab,
Jenkins, the JUnit reports of GitHub) read it. The same content as JSON:
curl -H "Authorization: Bearer $SWARMETRY_TOKEN" \
"https://swarmetry.io/api/v1/projects/$PROJECT_ID/runs/$RUN_ID/export?format=json"
This export does not use the reports of your plan. Before the end of the test it is refused with run.not_ended.
Errors
A refused call answers an HTTP status from 400 and a problem document (RFC 9457, Content-Type: application/problem+json). A program tests its code, which never changes; params gives the details of the code;
errors lists the wrong fields. detail, when present, is a note for developers, in English, not a message to show
to people.
A call without a token:
curl -i https://swarmetry.io/api/v1/projects
-i shows the status and the headers before the document (the first line reads HTTP/2 401 when your server
answers in HTTP/2):
HTTP/1.1 401 Unauthorized
Content-Type: application/problem+json
{"type":"about:blank","title":"Unauthorized","status":401,"code":"auth.unauthenticated"}
A test started without its scenario, and with a test configuration id that is not an id:
curl -i -X POST -H "Authorization: Bearer $SWARMETRY_TOKEN" -H "Content-Type: application/json" \
-d '{"testConfigId": "not-an-id"}' \
"https://swarmetry.io/api/v1/projects/$PROJECT_ID/runs"
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/problem+json
{"type":"about:blank","title":"Unprocessable Entity","status":422,"code":"request.invalid","errors":[{"location":"body","message":"expected required property scenarioId to be present","value":{"projectId":"019a6c1e-3f2b-7d4a-9c8e-5b1f0e2d4a61","testConfigId":"not-an-id"}},{"location":"body.testConfigId","message":"expected string to be RFC 4122 uuid: invalid UUID length: 9","value":"not-an-id"}]}
The codes a program meets most:
| Status | code |
What to do |
|---|---|---|
| 400 | request.malformed |
The body is not valid JSON: check the quotes |
| 401 | auth.unauthenticated |
No token, a wrong one, or it expired or was revoked: create a new one |
| 403 | auth.forbidden |
The token, or the person or service account it belongs to, may not do this; params says which permission |
| 403 | policy.ip_not_allowed |
Your address is outside the organization's allowed IP ranges (see below) |
| 403 | plan.feature_unavailable |
The plan of the organization does not include this feature |
| 404 | resource.not_found, or the kind of thing, such as run.not_found |
Nothing with this id in your organization (or you may not see it) |
| 409 | approval.required |
An approver must approve this action first (see Approvals) |
| 409 | run.not_ended |
The test has not ended yet: wait for its end |
| 422 | request.invalid |
Some fields are wrong or missing: each one is in errors, with its location (body for a missing field) |
| 429 | quota.exceeded |
A limit or quota of the plan is reached: waiting a minute does not help, params names the limit |
| 429 | request.rate_limited |
Too many requests: wait Retry-After seconds (see Rate limits) |
confirmation.required is only for the assistant and MCP clients, never for a call of the REST API.
Rate limits
By default, each token may send 3,000 requests per minute and each address 12,000; these numbers
may change. Over the limit, the answer is 429 with the
code request.rate_limited and a Retry-After header: the number of seconds to wait. Wait that long, never try again
at once in a loop.
curl does it for you with --retry: after a 429 it waits for Retry-After, then tries again (here at most 5
times):
curl --retry 5 -H "Authorization: Bearer $SWARMETRY_TOKEN" https://swarmetry.io/api/v1/projects
Without --retry, the refused answer looks like this:
HTTP/1.1 429 Too Many Requests
Content-Type: application/problem+json
Retry-After: 42
{"type":"about:blank","title":"Too Many Requests","status":429,"code":"request.rate_limited","params":{"retryAfterSeconds":42}}
In a program of your own, read Retry-After the same way. A quota.exceeded refusal (also 429) is a limit of your
plan, not of the request rate: trying again later does not help.
Pages of a list
Lists answer a page of items. While more remain, the answer also has nextCursor. Ask for a page size with limit
(1 to 200):
curl -H "Authorization: Bearer $SWARMETRY_TOKEN" \
"https://swarmetry.io/api/v1/projects?limit=1"
{
"items": [
{
"id": "019a6c1e-3f2b-7d4a-9c8e-5b1f0e2d4a61",
"name": "Shop"
}
],
"nextCursor": "AZpsHj8rfUqcjlsfDi1KYQ"
}
Send nextCursor back as cursor to get the next page:
export CURSOR='<next cursor>'
curl -H "Authorization: Bearer $SWARMETRY_TOKEN" \
"https://swarmetry.io/api/v1/projects?limit=1&cursor=$CURSOR"
The last page has no nextCursor. Keep the other parameters (here limit) the same from one page to the next.
Operations that cost or delete
The API reference marks the effect of every operation: read, write, destructive (it deletes or revokes something, and cannot be undone) or costly (it sends load or uses a quota of your plan, like starting a test).
Over the REST API, destructive and costly operations run at once. There is no confirmation question and no
confirmation field: by writing the call in a program, its author confirms it, as -y does for the command line. The
assistant and MCP clients show a confirmation form instead, and the command line asks Continue? [y/N]. What still
applies over the API: your permissions, the plan's limits and quotas, and the approval rules of your organization.
Approvals
Your organization may ask that tests be approved before they start (Administration > Approvals: every test, or tests above a number of virtual users). Then the start of step 3:
curl -X POST -H "Authorization: Bearer $SWARMETRY_TOKEN" -H "Content-Type: application/json" \
-d "{\"scenarioId\": \"$SCENARIO_ID\", \"testConfigId\": \"$TEST_CONFIG_ID\", \"note\": \"Started from the API\"}" \
"https://swarmetry.io/api/v1/projects/$PROJECT_ID/runs"
answers 409 and starts nothing. Swarmetry has created an approval request and tells the approvers:
{
"type": "about:blank",
"title": "Conflict",
"status": 409,
"code": "approval.required",
"params": {
"approvalId": "019a6c35-2b81-7a0e-8d4f-3c6e9b1a7f02",
"kind": "run.start"
}
}
An approver approves it in Administration > Approvals, or with their own personal token. Approvers are people (the organization's owners, or its administrators, as the rule says), never a service account:
export APPROVAL_ID='<approval id>'
export APPROVER_TOKEN='<token of the approver>'
curl -X POST -H "Authorization: Bearer $APPROVER_TOKEN" -H "Content-Type: application/json" \
-d '{"decision": "approve"}' \
"https://swarmetry.io/api/v1/approvals/$APPROVAL_ID/decision"
Then send the same start again: the test starts and uses the approval (once). The approval covers the same scenario with at most the same number of virtual users, until it expires.
Delete something
A destructive call, for example deleting a test configuration you no longer use:
export OLD_TEST_CONFIG_ID='<id of the test configuration to delete>'
curl -i -X DELETE -H "Authorization: Bearer $SWARMETRY_TOKEN" \
"https://swarmetry.io/api/v1/projects/$PROJECT_ID/scenarios/$SCENARIO_ID/test-configs/$OLD_TEST_CONFIG_ID"
HTTP/1.1 204 No Content
It is done at once: 204 means deleted, and there is no undo. The same call again answers 404
test_config.not_found.
Allowed IP ranges
If your organization only accepts some addresses (Administration > Security policies), every call with a token from
another address is refused with 403 policy.ip_not_allowed. Run your scripts from an allowed address, or ask an
administrator to add the address of the computer or CI runner that calls the API.