How to run API tests in CircleCI

CircleCI shows test results per job and tracks slow and flaky tests over time, as long as you give it JUnit XML. The Requestarium CLI writes exactly that from your saved API collections, so API tests can sit in the same dashboard as everything else.

Before you start

  1. In Requestarium, create an API token under Settings → API tokens (it starts with trt_).
  2. In CircleCI, open Project Settings → Environment Variables (or a shared Context) and add REQUESTARIUM_TOKEN, plus any key your requests need, such as STAGING_API_KEY.
The API tokens settings page with a new token named GitHub Actions, shown once with a Copy button
Create a dedicated token for CI in Settings → API tokens. It is shown only once.

The config

.circleci/config.yml:

YAML
version: 2.1

jobs:
  api-tests:
    docker:
      - image: cimg/node:22.11
    steps:
      - run:
          name: Install the Requestarium CLI
          command: npm install -g @requestarium/cli
      - run:
          name: Run API tests
          command: |
            mkdir -p test-results
            requestarium run-collection "Orders API" --env Staging \
              --env-var API_KEY=STAGING_API_KEY \
              --junit test-results/api.xml --html test-results/report.html --save-run
      - store_test_results:
          path: test-results
      - store_artifacts:
          path: test-results/report.html

workflows:
  build:
    jobs:
      - api-tests

What each part does:

  • The CLI reads REQUESTARIUM_TOKEN from the environment, so no login step is needed.
  • --env-var API_KEY=STAGING_API_KEY maps the CircleCI variable to {{API_KEY}} in your requests and masks it in reports.
  • store_test_results feeds the Tests tab. Every pm.test is a test case, and a request that couldn't be sent at all shows up as an error.
  • store_artifacts keeps the HTML report: totals, then every request with its tests, headers and response, with failures expanded.
  • --save-run stores the run in Requestarium with the branch, commit and a link to the CircleCI job.

Nightly runs

Add a scheduled trigger in Project Settings → Triggers, or a scheduled workflow, and run the full collection with a performance budget:

Terminal
requestarium run-collection "Orders API" --env Staging --max-p95 800 --retries 2 --save-run

--retries 2 resends requests that fail with a 502, 503 or 504, with exponential backoff, so a deploy in progress on staging doesn't fail the night's run. More in How to deal with flaky API tests.

Run many inputs

CircleCI is often used for broad regression runs. Run a collection once per row of a CSV file:

Terminal
requestarium run-collection "Users API" --env Staging --data tests/users.csv --junit test-results/api.xml

See Data-driven API tests with CSV and JSON files.