# Ridge Reports API

> Read, write and render reports, run schedules, manage sites and their members, and sign your application's users in to a site.

**Authentication.** Send an API key with each request: `Authorization: Bearer <key>`. Keys are created for a service account on a site's Members page or on the Users page, and can do whatever that account is allowed to do. The Discovery endpoints that describe this API and its specs need no key.

**Errors.** An error comes back with a message in `error` and, for most errors, a `code` your application can act on. A `404` can also mean that the account has no access.

**Base URL.** `https://demo.ridgereports.com/api/v1`. The API document writes each path in full, from `/api/v1`. This file and the specs it links need no API key; everything else does.

**AI apps.** A person connects their own AI app (Claude, ChatGPT, Claude Code and others) at the MCP address `https://demo.ridgereports.com/mcp`, signing in as themselves. Its tools are this API's endpoints, and it can do what that person can do. No API key is involved.

**A first session.**

1. `GET /me` checks the key: it returns the account, the key, and the sites the account is a member of.
2. Read the instructions the administrators wrote for programs and AI: `GET /instructions` returns the deployment's, to read before acting, and `GET /sites/{slug}/instructions` a site's, to read before working in it: knowledge articles in full, some of them for particular data sources. A site's add to the deployment's, and a data source's add to the site's; where they disagree, the narrower one applies. None of them changes what the API allows.
3. Read what the site's knowledge base says about the task. A site's instructions end with the other knowledge articles the account can read, each with its ID and summary: reference material about the site's data and conventions, such as what the tables mean, how they join and example queries. Each data source in `GET /sites/{slug}/data-sources` names the articles about it. `GET /sites/{slug}/knowledge-articles/{knowledge_article_id}` returns an article in full, to read before writing a query or a report, and `GET /sites/{slug}/knowledge-articles` lists them again, with `tag` to filter them. An account that administers the site also writes them: `POST` on the list's path creates an article, and `PUT` and `DELETE` on an article's path replace and delete it. Readers see a change at once, so make one only when asked to.
4. `GET /sites/{slug}/reports?published=true` lists a site's published reports that the account can read.
5. `GET /sites/{slug}/reports/{report_id}/parameters` says what a report asks for.
6. `POST /sites/{slug}/reports/{report_id}/render` renders it to a file, with the values in `parameters`, keyed by name, and the file type in `format` (`pdf` unless given).

**Writing a report.** A report is written through the account's own draft of it, which nobody else sees: readers keep seeing the published version until the draft is published. The account needs the right to edit the report.

1. Read the report document schema and the expression language, linked below: what a report document holds, and how it computes what it shows.
2. Find the report, or create one: `GET /sites/{slug}/reports?published=false` lists the reports not yet published, and `POST /sites/{slug}/reports` creates a report. `POST /sites/{slug}/reports/import-rdl` creates one from an RDL file, from SQL Server Reporting Services or Bold Reports; its `notes` say what to correct in the draft.
3. `GET /sites/{slug}/reports/{report_id}/draft` returns the document and the draft's `version`, and starts the draft if the account has none.
4. Find the data: `GET /sites/{slug}/data-sources` lists the data sources the account can use, each with the knowledge articles about it, `GET /sites/{slug}/data-sources/{data_source_id}/catalog` lists the tables of one, and `POST /sites/{slug}/reports/{report_id}/draft/sample` tries a query and returns its first rows.
5. `PUT /sites/{slug}/reports/{report_id}/draft/assets/{name}` adds an image, which the document shows as `asset:<name>`.
6. `PUT /sites/{slug}/reports/{report_id}/draft` saves the document, and `PATCH` on the same path changes part of it by `operations`, a JSON Patch (RFC 6902), without sending it whole: use it for a targeted change, and start the operations with a `test` on the `id` at the position changed, since items are addressed by position. Every change to the draft names the version it is based on as `expected_version`, and answers with the next one. A `409` means the draft changed in the meantime: read it again and reapply the change.
7. `POST /sites/{slug}/reports/{report_id}/draft/render` with `Accept: application/json` renders the draft and returns the file with its `warnings`: each value that could not be evaluated, by its item's `item_id` and the `path` within the item. A draft that cannot run is refused with what is wrong. Correct the document and save it again.
8. `POST /sites/{slug}/reports/{report_id}/revisions` saves the draft as a named revision, which a person can preview and publish from the report's history, and `POST /sites/{slug}/reports/{report_id}/publish` publishes it, which changes what readers see, as `POST /sites/{slug}/reports/{report_id}/unpublish` does by taking a report back from them: do any of these only when asked to.

For text, prefer the font families `Ridge Sans`, `Ridge Serif` and `Ridge Mono`, which have every weight and the condensed widths.

**Moving reports.** `GET /sites/{slug}/reports/{report_id}/export` returns a report as a `.ridge` file, with its images and the reports it embeds, and `POST /sites/{slug}/reports/import` creates new reports from one, in another site or the same one. Its `notes` say what to correct in each new report's draft. Importing publishes nothing unless asked to with `publish`.

## Specs

- [API, version 1 (OpenAPI 3.1)](https://demo.ridgereports.com/api/v1/specs/api.v1.openapi.json): Every endpoint of this API, with its parameters, request and response bodies, and errors.
- [Report document, version 1 (JSON Schema)](https://demo.ridgereports.com/api/v1/specs/report.v1.schema.json): The definition of a report: its page, items, tables, charts, datasets and parameters. A document states the version it follows in `schemaVersion`.
- [Expression language, version 1](https://demo.ridgereports.com/api/v1/specs/expr.v1.md): How a report document computes what it shows: the `=` and `{{ }}` forms, types, operators, names, aggregates, format patterns, errors and every function.

## Optional

- [Expression functions, version 1 (JSON)](https://demo.ridgereports.com/api/v1/specs/expr.v1.functions.json): Every function of the expression language as data: its signature, parameters, description and examples.
- [Archive format, version 1](https://demo.ridgereports.com/api/v1/specs/archive.v1.md): The `.ridge` file reports move between sites in: a zip with a manifest and a folder per report, its images, and the data sources and shared images it uses.
- [Archive manifest, version 1 (JSON Schema)](https://demo.ridgereports.com/api/v1/specs/archive.v1.schema.json): The `manifest.json` of a `.ridge` file, and under `$defs` the file of each kind of item it holds.
- [API reference](https://demo.ridgereports.com/api-docs): The endpoints of the API document, written for people.
