Get a signed callback when a server-side API test run finishes

The Run API can wait up to 60 seconds for a run to finish. Longer runs, or callers that shouldn't hold a connection open (a deploy tool, a serverless function, a chat bot), are better served by a callback: start the run, return, and get a POST when it's done.

Start a run with a callback

Terminal
curl -sS https://api.requestarium.com/api/v1/runs \
  -H "Authorization: Bearer $REQUESTARIUM_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: release-$RELEASE_ID" \
  -d "{
    \"workspace_id\": \"$WORKSPACE_ID\",
    \"target\": { \"kind\": \"suite\", \"id\": \"$SUITE_ID\" },
    \"callback_url\": \"https://deploy-bot.example.com/hooks/requestarium\",
    \"callback_secret\": \"$CALLBACK_SECRET\"
  }"

Without wait, the answer is 202 Accepted with a Location to poll, which you can ignore when you rely on the callback. The target can be a collection, folder, suite or flow.

The token is an organization API token (trs_…) with the write scope, or a personal token. See organization API tokens for CI.

What arrives

JSON
{
  "event": "run.finished",
  "run": {
    "id": "6474…",
    "status": "failed",
    "summary": { "total": 24, "passed": 23, "failed": 1, "errors": 0, "duration_ms": 5321 }
  }
}

status is passed, failed, error or cancelled. For the per-request results, fetch GET /api/v1/runs/{id}; for a test report, GET /api/v1/runs/{id}/junit.

Verify the signature

The signature is an HMAC-SHA256 of the raw request body, keyed with your callback_secret, hex-encoded. Compute it over the bytes you received, before parsing JSON, and compare in constant time:

JavaScript
import crypto from 'node:crypto';
import express from 'express';

const app = express();
const secret = process.env.CALLBACK_SECRET;

app.post('/hooks/requestarium', express.raw({ type: 'application/json' }), async (req, res) => {
  const expected = 'sha256=' + crypto.createHmac('sha256', secret).update(req.body).digest('hex');
  const got = req.get('X-Requestarium-Signature-256') || '';
  const ok = got.length === expected.length && crypto.timingSafeEqual(Buffer.from(got), Buffer.from(expected));
  if (!ok) return res.status(401).end();

  const { event, run } = JSON.parse(req.body.toString('utf8'));
  res.status(204).end(); // answer fast, then do the work

  if (event === 'run.finished' && run.status !== 'passed') {
    await notifyReleaseChannel(run); // your code
  }
});

app.listen(3000);

Two common mistakes: computing the HMAC over re-serialized JSON (key order and spacing change, so it never matches), and comparing with ===, which leaks timing.

Answer fast

Return a 2xx quickly and do slow work afterwards. A failed delivery is retried twice, after 5 and 30 seconds; after that the callback is dropped, and the run is still there to read with GET /api/v1/runs/{id}. Because of retries, make the handler safe to call twice for the same run id.

Callback or notifications?

The callback belongs to one run you started. For "tell us about every failed run of this suite, wherever it ran", use run notifications instead: Slack, Teams, a webhook or a flow, on failed, recovered or every run. See receiving test-run webhooks.

Limits

60 runs started per minute per token, 2 runs at a time per organization (more wait in the queue), 10 minutes per run. The server sends the requests, so the APIs under test must be reachable from it.