# Read audit runs, findings, and coverage

> Follow Sonjoo run states, distinguish runId from auditId, and retrieve per-URL evidence and saved reports.

Canonical documentation: <https://sajaddehshiri.ir/sonjoo-seo-audit/api/runs-and-findings/>

A run tracks one execution. Its `runId` is available as soon as the server accepts the request. A saved report gets a separate `auditId` for history and exports.

## Follow a run to completion

1. Send `POST /api/runs`. HTTP `202` accepts the run and supplies `runId`. The `Location` header points to `/api/runs/current`.
2. Poll `GET /api/runs/:runId` while `status` is `running`. Give the polling loop a deadline.
3. When `status` is `complete`, fetch `GET /api/runs/:runId/result`. For `cancelled` or `error`, stop polling and inspect the returned state.
4. If the state includes `auditId`, it can be used for a durable lookup at `GET /api/audits/:id`.

Sonjoo runs one audit at a time. A second start request returns HTTP `409` while a run is active. `DELETE /api/runs/current` requests cancellation. The run status records when cancellation completes.

## Read findings and URL evidence

The result response contains a `result` object. Under `result.categoryResults[].results[]`, look for a rule's `ruleId`, `status`, `message`, and any `details` available. For an example with a single missing title, see the [quickstart's expected evidence](https://sajaddehshiri.ir/sonjoo-seo-audit/api/quickstart/#expected-evidence).

Crawl views aggregate results by rule and include a bounded `samplePages` array. Query `/api/audits/:id/rules/:ruleId/pages` for per-URL evidence on a saved report, including unmeasured rows. Use `/api/runs/:runId/rules/:ruleId/pages` for the retained result. Paginate to collect the full returned inventory.

Check `result.completionState`, `result.coverage`, and `result.ruleCoverage` before drawing conclusions. A complete run can contain partial measurement, warnings, or failed rules. If saving fails, the run can complete with a retained report and a `save-failed` status in `state.error.code`. The result view provides its own measurement coverage.

## Retain, export, and compare

API audits save by default. Use `save: false` for a temporary result. The current or most recent result can be retrieved for up to 15 minutes or until another run starts. Use the saved audit ID when an integration needs a durable result.

* Export with `GET /api/audits/:id/export?format=json` for a saved report envelope, or `GET /api/runs/:runId/export?format=json` for the retained report itself. The retained download uses `application/octet-stream` even when its body is JSON. Both export routes default to HTML and also accept `markdown` and `llm`.
* Use `POST /api/runs/:runId/save` to save an available unsaved result. Capture the returned `auditId`.
* Use `GET /api/audits/:id/compare?against=<id>` for a saved report comparison. Omit `against` to use the prior audit chosen by Sonjoo.
* Use the `crawl` routes for a crawl's URL inventory, filters, link views, and CSV output. The [route reference](https://sajaddehshiri.ir/sonjoo-seo-audit/api/reference/#routes) lists both forms.
* `DELETE /api/audits/:id` removes the saved history item. If its run is still retained, the report can remain available temporarily through that run ID.

## Stream progress

`GET /api/events` opens an authenticated server-sent event stream. It sends an initial `snapshot`, then `state` updates and periodic `heartbeat` events. The server allows up to eight simultaneous streams. Polling by `runId` works well for terminal scripts and CI.
