# Running a collection

> Run a folder or a whole API collection in order, like Postman's runner: iterations, a data file, a delay, and dockito run for CI.

The runner sends the requests in a folder, or the whole collection, one after another, with their [scripts](/help/api-docs/scripts) and tests, and shows how each went.

## Run from the desktop app

In the **Dockito desktop app**, choose ▶ at the top of the requests, or **Run folder** on a folder's menu. Then:

- **Pick the requests:** untick any to leave it out, and drag to change the order.
- **Iterations:** how many times to run them.
- **Data file:** a CSV (a header row, then a row an iteration) or JSON (a list of objects). Each row is `pm.iterationData` for its iteration, and its columns fill `{{column}}`. With a data file, iterations default to its rows.
- **Delay:** milliseconds to wait between requests.
- **Stop on first failure:** a failed test, a script error or a request that couldn't be sent ends the run.
- **Keep variable values:** keep what scripts set when the run ends, or put things back as they were.

Choose **Run**, and **Cancel** stops it at any time. In the browser, the runner works the same way for people who can edit the doc, when the API lets browsers read its answers, but scripts don't run there: the results say so. Its results stay in this browser.

A request whose URL uses a `{{variable}}` with no value isn't sent: the runner says which ("baseUrl isn't set"), and when the collection has environments and none is picked, offers one to pick right there. The same goes for **Send** on a single request.

## Results

Each request shows its status, time and size, and its tests in words ("1 of 2 tests passed"). A request marked failed always says why on its row: the error, the script error, or the failed test. The totals sit on top; **Failed** shows only what failed. **Copy for AI** copies the run in a few lines: the failures in full, the passes counted, secrets by name only. With an AI set up in the desktop app, **Add to chat** attaches the run to the AI panel instead: each request's status, time and size, why any failed, and the start of each body, with keys and Authorization or Cookie values hidden.

The last 20 runs of a doc stay on your computer (200 in all), under **Past runs on this computer**.

## Steering the run from a script

`pm.execution.setNextRequest("Get booking")` (or `postman.setNextRequest`) runs that request next, by name or ID, so a script can loop or skip ahead. `setNextRequest(null)` ends the current iteration. Values set with `pm.variables` and `pm.globals` last for the whole run.

## From a terminal or CI

The CLI runs the same scripts with the same rules, on your machine:

```sh
dockito run <doc> "Create booking" --env Staging     # one request, with its scripts
dockito run <doc> Bookings --env Staging --data guests.csv --bail
dockito run <doc> - --reporter junit > results.xml   # - is the whole collection
```

- `--iterations <n>`, `--data <file>`, `--delay <ms>`, `--bail`: as in the app.
- `--reporter cli` (the default) prints each request as it ends and then the run in a few lines; `json` prints the whole run; `junit` writes JUnit XML for CI.
- The exit code is 1 when a test failed, a script errored or a request couldn't be sent.

Secrets come from the environment (`BOOKINGS_TOKEN`) or what `dockito env set` kept in your keychain, never from Dockito. The CLI doesn't keep values scripts set.

To run a collection on a schedule, on your Mac or in CI, use [monitors](/help/api-docs/monitors).

## OAuth 2 in a run

A request with OAuth 2 gets its token before it's sent, in the app and in `dockito run`, as when you send it alone. With client credentials or a password, the run gets a token from the token URL once and every request with that auth uses it. In the app, an expired token is refreshed first when a refresh token is kept, and the new token is kept for next time. An authorization code needs **Get new token** first, since a run opens no browser. If a token can't be had, that request fails and says why; `--bail` stops the run there. Tokens never appear in the run's results.
