
Run API Tests From the Command Line (No GUI)
Short answer: to run API tests from the command line without a GUI client, write the test as a file, run it with one command, and let the exit code and a report tell you the result. With the DevTools CLI that command is devtools flow run <file>, and the file is a YAML flow that chains requests and asserts on each response.
This guide goes from an empty folder to a passing end-to-end run in a terminal: install, write a four-step flow, read the result, then run the same command in CI.
Install the CLI and run a flow
The DevTools CLI is free, runs on your own machine and in your own CI, and needs no account. On macOS and Linux the install script installs the CLI:
curl -fsSL https://sh.dev.tools/install.sh | bash
devtools version
The CLI reference also points to a releases page with a binary for your operating system.
Running a test is one command. The first argument is the flow file and the second, optional one is the name of a single flow. When you leave the name out, the CLI runs every flow listed in the file's run field, in order.
devtools flow run items.yaml
devtools flow run items.yaml ItemLifecycle
The first form runs everything the file lists, and the second runs one flow by name. Nothing opens a window, so the same line works in a terminal, a script or a pipeline.
Write an end-to-end test as a YAML file
A single request tells you little. An end-to-end test follows the life of a resource: log in, create something, read it back, delete it. The file below does that against a placeholder API. Later steps read earlier responses with {{ StepName.response.body.field }}.
workspace_name: Items API
run:
- flow: ItemLifecycle
flows:
- name: ItemLifecycle
steps:
- manual_start:
name: Start
- request:
name: Login
depends_on: Start
method: POST
url: '{{ #env:BASE_URL }}/login'
body:
type: json
json:
email: '{{ #env:API_USER }}'
password: '{{ #env:API_PASSWORD }}'
assertions:
- response.status == 200
- request:
name: CreateItem
depends_on: Login
method: POST
url: '{{ #env:BASE_URL }}/items'
headers:
Authorization: 'Bearer {{ Login.response.body.token }}'
body:
type: json
json:
name: Test Item
assertions:
- response.status == 201
- request:
name: GetItem
depends_on: CreateItem
method: GET
url: '{{ #env:BASE_URL }}/items/{{ CreateItem.response.body.id }}'
headers:
Authorization: 'Bearer {{ Login.response.body.token }}'
assertions:
- response.status == 200
- response.body.name == "Test Item"
- request:
name: DeleteItem
depends_on: GetItem
method: DELETE
url: '{{ #env:BASE_URL }}/items/{{ CreateItem.response.body.id }}'
headers:
Authorization: 'Bearer {{ Login.response.body.token }}'
assertions:
- response.status == 204
Three details make this a test and not a script. First, the token from Login and the id from CreateItem flow into later requests by reference, so nothing is pasted by hand. Second, every request carries assertions, which are expressions such as response.status == 200. A request step whose assertion fails ends with an error. Third, the base URL and credentials come from {{ #env:NAME }} references, so the file holds no secrets and can sit in version control.
If a referenced variable is not set, the CLI reports the missing environment variables and tells you to set them or add them to a .env file. Set them for a local run like this:
export BASE_URL=https://api.example.com API_USER=ci-user API_PASSWORD=...
devtools flow run items.yaml
For a longer walk through chaining and negative cases, see building an end-to-end API test, and for the assertion syntax see API assertions in YAML.
Read the result: exit code and reports
A run that passes exits with status 0, and a run that fails exits with 1. That is the whole contract a shell script or a CI job needs:
if devtools flow run items.yaml; then
echo "API tests passed"
else
echo "API tests failed" >&2
exit 1
fi
The console report is the default. The --report flag takes a format and an optional path in the form format:path, and the supported formats are console, json and junit. Repeat the flag to write several outputs in one run:
devtools flow run items.yaml \
--report console \
--report json:results.json \
--report junit:results.xml
The JSON file is meant for programmatic parsing, and the JUnit XML file is meant for CI systems. Add --quiet or -q in a pipeline when you want the console output suppressed, so only the exit code and the report files matter.
Where the first flow file comes from
You can write the YAML by hand, as above, but you do not have to start from a blank file. DevTools records real traffic and auto-maps variables between steps, which gives you a starting point instead of a blank file. The related guides cover the two usual starting points: capturing a HAR file from a browser session, and turning curl commands into tests when you already have the calls in your shell history. Either way, the file ends up in your repository and the command stays the same.
Debug a failing run
A red run is usually one of three things: a missing variable, a failed assertion, or an unreachable server. Start with the cheapest check. Run the one flow by name so the output stays short, and add --show-output, which prints each node's output data after the node completes.
devtools flow run items.yaml ItemLifecycle --show-output
Read the console output top to bottom. The first step that fails is the cause, because every later step depends on it. A GetItem failure that follows a passing CreateItem points at the read path of your API. A Login failure points at credentials or the base URL. Fix that step, run again, and only then look at the rest.
Run the same command in CI
Nothing about the command changes in a pipeline. The job installs the CLI, runs the file, and uploads the report. This GitHub Actions job runs the flow from above and keeps the JUnit file even when a test fails:
name: api-tests
on:
pull_request:
jobs:
api:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Install the DevTools CLI
run: curl -fsSL https://sh.dev.tools/install.sh | bash
- name: Run API tests
env:
BASE_URL: ${{ secrets.BASE_URL }}
API_USER: ${{ secrets.API_USER }}
API_PASSWORD: ${{ secrets.API_PASSWORD }}
run: devtools flow run items.yaml --report junit:out/junit.xml
- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: api-test-reports
path: out/
The job fails when the command exits with 1, which is what makes the pull request check go red. The CLI page shows the same JUnit invocation, devtools flow run --report junit:test-results.xml tests.yaml. To turn the JUnit file into annotated failures on the pull request, read JUnit reports in GitHub Actions. For caching, parallel jobs and a copy-paste workflow, see GitHub Actions for YAML API tests.
How this compares with curl, HTTPie, Postman CLI, Newman and Karate
Each tool below can be run without a GUI. What differs is what the tool does with a response, and each description here comes from that tool's own documentation.
- curl is a tool for transferring data from or to a server using URLs. With
--fail, curl fails with error code 22 for HTTP responses at 400 or greater. Anything beyond that status check is yours to script in shell. The related walkthrough is turning curl commands into repeatable API tests. - HTTPie is designed for testing, debugging and generally interacting with APIs and HTTP servers. Its
--check-statusflag makes it exit with an error on 3xx, 4xx or 5xx responses. - Postman CLI is used to run Postman collections to test the functionality of your API. Its documentation lists three ways to send results to Postman: sign in with
postman login, pass--postman-api-key, or setPOSTMAN_API_KEY. - Newman is a command-line collection runner for Postman, and its JUnit reporter is turned on with
--reporters junit. - Karate describes itself as an open-source tool that combines API testing, mocks, performance testing and UI automation.
The choice depends on where your tests already live. If they are Postman collections, Postman CLI or Newman run them as they are. If you want plain request-and-check scripts, curl and HTTPie are enough. If you want multi-step tests stored as YAML next to your code, with an exit code and JUnit output from a free local CLI, that is the case the flow above covers. For a wider tool list, see best command line tools for CI.
Common questions
How do I run just one flow from a file?
Pass its name after the file: devtools flow run items.yaml ItemLifecycle. Without a name, the CLI runs every flow in the file's run field in order.
How do I keep passwords out of the YAML file?
Reference them as {{ #env:NAME }} and set them in the environment or in a .env file. The CLI reports any missing variable by name.
Does the CLI need an account or a hosted service?
No. The CLI is free, runs on your own machine and in your own CI, and needs no account.
How do I get a JUnit report from the command line?
Add --report junit:results.xml to the run command. The format is format:path, and json and console work the same way.
