Appearance
Automate with the API
After a change to FreeSWITCH or Kamailio you want to know at once whether calls still work. Everything you do in the PBXsight UI can also be done by a script: start a test, wait for the verdict, download the report. This page gets you there in three steps; the API reference lists every endpoint.
You need curl and jq on the machine that runs the script, and that machine must reach PBXsight's address.
First step: open your Account page and create a token (1. Create a token).
Quick start
1. Create a token
Click your name at the right of the top bar → Account → API tokens. Give it a name that says what uses it (e.g. gitlab-ci), keep the role Operator (it may start tests) and click Create token.

The token (pbxs_…) is shown only once: copy it into your CI's secret store or a shell variable. PBXsight keeps only a fingerprint of it and can't show it again — if you lose it, revoke it and create a new one.
sh
export PBXSIGHT_URL=http://127.0.0.1:8080 # the address you open PBXsight on
export PBXSIGHT_TOKEN=pbxs_… # the token you just copiedCheck that it works:
sh
curl -s -H "Authorization: Bearer $PBXSIGHT_TOKEN" "$PBXSIGHT_URL/api/auth/me"json
{"id": 3, "username": "anna", "role": "operator", "via_token": {"name": "gitlab-ci", "role": "operator"}}2. Save the test you want to run
The easiest test to automate is a saved test: on the Schedules page create a schedule with the test you want (e.g. 10 calls to the echo test) and switch it off — then it never runs by itself, only when your script asks. Its number is in the page address (/schedules/4 → id 4), or list them:
sh
curl -s -H "Authorization: Bearer $PBXSIGHT_TOKEN" "$PBXSIGHT_URL/api/schedules" \
| jq -r '.[] | "\(.id)\t\(.name)"'4 echo test after changes3. Run it and wait for the verdict
sh
curl -s -X POST -H "Authorization: Bearer $PBXSIGHT_TOKEN" \
"$PBXSIGHT_URL/api/schedules/4/run?wait=10m"The request starts the test and returns when it has finished (at most after 10 minutes):
json
{
"id": "20261130-151047-t8s7",
"type": "call",
"profile": "default",
"status": "completed",
"finished": true,
"verdict": "passed",
"exit_code": 0,
"reason": "verdict passed (2 of 2 checks passed)",
"checks": [
{"name": "Answer rate", "op": ">=", "threshold": 99, "value": 100, "unit": "%", "status": "passed"},
{"name": "Setup time p95", "op": "<=", "threshold": 500, "value": 2.8, "unit": "ms", "status": "passed"}
],
"report_url": "/api/tests/20261130-151047-t8s7/export?format=html",
"run_url": "/tests/20261130-151047-t8s7"
}exit_code is all a script has to look at:
exit_code | Meaning | What a CI job does |
|---|---|---|
| 0 | finished, the test passed (or it has no criteria) | pass |
| 1 | finished, the test failed — reason says which check | fail |
| 2 | the run broke off with an error, or someone stopped it | fail |
| 3 | still running — the wait ended first | ask again (below) |
That's it. The rest of this page is a ready-made script for CI and a few more recipes.
A CI gate script
Save this as ci/pbxsight-gate.sh in your repository. It runs saved test SCHEDULE_ID, waits for it, prints the checks, saves the HTML report and exits with the result's exit code — so the CI job fails when the test fails.
sh
#!/bin/sh
set -eu
: "${PBXSIGHT_URL:?}" "${PBXSIGHT_TOKEN:?}"
AUTH="Authorization: Bearer $PBXSIGHT_TOKEN"
SCHEDULE_ID=${SCHEDULE_ID:-4}
# start the saved test and wait up to 10 minutes
res=$(curl -sS --fail-with-body -X POST -H "$AUTH" \
"$PBXSIGHT_URL/api/schedules/$SCHEDULE_ID/run?wait=10m")
id=$(echo "$res" | jq -r .id)
# longer tests (busy hour, find the limit): keep waiting while it runs
while [ "$(echo "$res" | jq .exit_code)" -eq 3 ]; do
res=$(curl -sS --fail-with-body -H "$AUTH" "$PBXSIGHT_URL/api/tests/$id/result?wait=10m")
done
echo "$res" | jq -r '"PBXsight run \(.id): \(.status), verdict \(.verdict) — \(.reason)"'
echo "$res" | jq -r '.checks[] | " \(.status)\t\(.name): \(.value) (\(.op) \(.threshold) \(.unit // ""))"'
# the self-contained HTML report as a CI artifact
curl -sS --fail -H "$AUTH" -o pbxsight-report.html \
"$PBXSIGHT_URL/api/tests/$id/export?format=html&download=1" || echo "no report"
exit "$(echo "$res" | jq .exit_code)"When PBXsight can't be reached, the token is wrong, there's no valid licence or another test is running, curl fails and so does the job — with PBXsight's message in the log.
GitHub Actions
The runner must reach PBXsight (usually a self-hosted runner in your network). Store the token as the secret PBXSIGHT_TOKEN and the address as the variable PBXSIGHT_URL.
yaml
jobs:
pbx-gate:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- name: PBXsight test
env:
PBXSIGHT_URL: ${{ vars.PBXSIGHT_URL }}
PBXSIGHT_TOKEN: ${{ secrets.PBXSIGHT_TOKEN }}
run: sh ci/pbxsight-gate.sh
- name: PBXsight report
if: always()
uses: actions/upload-artifact@v4
with:
name: pbxsight-report
path: pbxsight-report.html
if-no-files-found: ignoreGitLab CI
Set PBXSIGHT_URL and PBXSIGHT_TOKEN (masked) under Settings → CI/CD → Variables.
yaml
pbxsight-gate:
stage: test
image: alpine:3.20
before_script:
- apk add --no-cache curl jq
script:
- sh ci/pbxsight-gate.sh
artifacts:
when: always
paths:
- pbxsight-report.htmlMore recipes
All examples assume PBXSIGHT_URL and PBXSIGHT_TOKEN are set, and
sh
AUTH="Authorization: Bearer $PBXSIGHT_TOKEN"The last runs and their verdicts
sh
curl -s -H "$AUTH" "$PBXSIGHT_URL/api/tests?limit=5" \
| jq -r '.[] | [.id, .type, .status, (.summary.verdict.result // "-")] | @tsv'20261130-151047-t8s7 call completed passed
20261130-151030-yu1l call stopped passed
20261130-151021-q2nq call completed failedOne run's result
sh
curl -s -H "$AUTH" "$PBXSIGHT_URL/api/tests/20261130-151047-t8s7/result"The same answer as in step 3. Add ?wait=10m to wait for a run that is still going.
A test that isn't saved
Send the test's settings as JSON instead of using a saved test:
sh
curl -s -H "$AUTH" -H 'Content-Type: application/json' \
-d @echo-test.json "$PBXSIGHT_URL/api/tests?wait=10m"with echo-test.json:
json
{
"type": "call",
"profile_id": 1,
"extension_set_id": 3,
"call": {"destination": "9196", "callers": 2, "cps": 1, "hold_seconds": 10,
"mode": "total", "total_calls": 10}
}Tip: start the test once in the UI, then copy its settings — params.request of the run is exactly this JSON:
sh
curl -s -H "$AUTH" "$PBXSIGHT_URL/api/tests/20261130-151047-t8s7" | jq .params.requestAll fields per test type: Start a test.
Stop a running test
sh
curl -s -X POST -H "$AUTH" "$PBXSIGHT_URL/api/tests/20261130-151047-t8s7/stop"Download a report or the data
sh
# HTML report (one self-contained file)
curl -s -H "$AUTH" -o report.html "$PBXSIGHT_URL/api/tests/$ID/export?format=html&download=1"
# everything as JSON
curl -s -H "$AUTH" -o run.json "$PBXSIGHT_URL/api/tests/$ID/export?format=json"
# all runs as a spreadsheet (CSV)
curl -s -H "$AUTH" -o runs.csv "$PBXSIGHT_URL/api/tests/export?format=csv"Long tests
One request waits at most 10 minutes. A busy hour or find-the-limit test runs longer: when the answer has exit_code 3, ask again with the run's id — the gate script above does this in its while loop:
sh
curl -s -H "$AUTH" "$PBXSIGHT_URL/api/tests/$ID/result?wait=10m"A dropped connection (CI timeout, network) ends only the waiting, never the test.
Managing tokens
The Account page lists your tokens with their role, their first characters (so you can tell which one is in which CI secret), when they were last used and from which address, and when they expire. Revoke stops a token at once.
What to know about tokens:
- A token acts as you, with the role you gave it. If your own role is lowered later, the token's is too.
- Choose the lowest role that works: Viewer reads results, Operator also starts and stops tests, Admin also changes profiles and settings.
- Tokens can't manage logins: no token — not even an admin's — can create users or tokens or change passwords. That needs the browser.
- Tokens are separate from your browser login: logging in elsewhere, logging out or changing your password doesn't affect them. They stop when you revoke them, when they expire, or when your account is disabled or deleted.
- The activity log shows actions done with a token under your name with
[token NAME]added. - Admins see how many tokens each user has on the Users page and can revoke all of a user's tokens at once (e.g. when someone leaves). See Users and roles.
Things to know
- The HTTP status is 200 for every verdict — a failed test is still a successful request. Use
exit_code, notcurl --fail, to fail a job;curl --failcatches only the errors below. - Errors come as
{"error": "…", "details": […]}. The ones a script meets:401wrong or expired token,402no valid licence,409another test is running,422invalid test settings (every problem indetails),429too many wrong tokens from this address (wait 15 minutes). - One test at a time. A start while another test runs is refused, not queued: plan CI jobs so they don't overlap with long scheduled tests. The always-on watch runs beside tests and never causes a
409. - Timeouts. Behind a reverse proxy, its read timeout must be longer than the wait (or wait less per request, e.g.
?wait=2m, and loop). The CI step's own timeout must cover the whole test. - When PBXsight restarts during a test, the test ends as failed (
exit_code2 when you ask again) and a waiting script fails; run the job again. - A stopped run has
exit_code2 even when its checks so far passed — it didn't complete. - Links in the answer (
report_url,run_url) are full addresses when the app URL of the e-mail alert settings is set. - HTTPS with a self-signed certificate: give curl the certificate (
--cacert pbxsight.crt) rather than-k. See HTTPS and remote access. - The always-on watch can't be started this way; its daily runs can be read with
/result. - Don't place test calls against a production PBX from CI without checking the destinations and the safety limits of the profile first.