# Check your first draft

Source: https://watership.ca/api-docs/docs/tutorials/check-your-first-draft

Start the mock server, check a short draft, read the findings, and look up the rule behind one of them. About 15 minutes.

In this tutorial, you check a short help article against the Watership rules. By the end, you'll have sent an authenticated request, read a list of findings, looked up the rule behind a finding, and done the same check from a script.

You don't need to know anything about Watership. You need:

- Node.js 24.18 or later, and npm
- `curl`
- A copy of [the API docs repository](https://watership.ca/parts.html#api-docs), which holds the spec and the mock server

<Callout title="About the mock server">
  The hosted API doesn't exist yet, so you'll run a mock server on your own computer. The mock doesn't run the checks. It answers every request with the example response from the API spec. The example for a check is the real check engine's output for the draft in this tutorial, which is why you'll use that exact draft.
</Callout>

<Steps>
<Step>

## Start the mock server [#start-the-mock-server]

In the repository folder, install the dependencies and start the mock:

```sh
npm install
npm run mock
```

When the mock is ready, it prints a line for each endpoint, such as `POST http://127.0.0.1:4010/v1/checks`. Leave it running, and open a second terminal for the rest of the tutorial.

</Step>
<Step>

## Send a request without a key [#send-a-request-without-a-key]

Every request needs an API key. To see what happens without one, ask for the list of voices:

```sh
curl -i http://127.0.0.1:4010/v1/voices
```

The response is `401 Unauthorized`, with a body like this:

```json
{
  "type": "https://watership.ca/api/problems/unauthorized",
  "title": "Authentication failed",
  "status": 401,
  "detail": "Send your API key in the Authorization header as \"Bearer <key>\".",
  "instance": "req_5Lr1cN8eQ4"
}
```

Every error from the API has this shape. The `type` says what kind of problem it is, and the `detail` says what to do about it.

</Step>
<Step>

## Add a key [#add-a-key]

Send the same request with a key in the `Authorization` header. The mock accepts any key, so use `wsk_test_tutorial`:

```sh
curl http://127.0.0.1:4010/v1/voices \
  -H "Authorization: Bearer wsk_test_tutorial"
```

This time you get `200 OK` and a list of voices. You're ready to check some text.

</Step>
<Step>

## Check the draft [#check-the-draft]

Here's the draft you'll check. It's a short help article with problems a reviewer would catch:

```md title="draft.md"
# Getting Started With Exports

It's important to note that you can easily utilize the export tool. It allows you to download a seamless copy of your data. Please click Export to begin.

Exports finish within a day; it is rare for one to fail. The next maintenance window is 11/04/2026.
```

A check request is JSON with the text in a `text` field. Save this as `check.json`:

```json title="check.json"
{
  "text": "# Getting Started With Exports\n\nIt's important to note that you can easily utilize the export tool. It allows you to download a seamless copy of your data. Please click Export to begin.\n\nExports finish within a day; it is rare for one to fail. The next maintenance window is 11/04/2026.\n",
  "format": "markdown"
}
```

Send it to `POST /v1/checks`:

```sh
curl http://127.0.0.1:4010/v1/checks \
  -H "Authorization: Bearer wsk_test_tutorial" \
  -H "Content-Type: application/json" \
  --data @check.json
```

The response starts with a summary:

```json
{
  "release": "0.3.3",
  "engine_version": "1.0.0",
  "counts": { "error": 1, "warning": 8, "suggestion": 2 },
  "truncated": false,
  "findings": [ ... ]
}
```

`counts` gives the number of findings at each level, and `findings` lists them in the order they appear in the draft.

</Step>
<Step>

## Read a finding [#read-a-finding]

Find the item in `findings` whose `level` is `error`. It's the only error:

```json
{
  "check": "SlashDates",
  "style": "Watership",
  "rule_ids": ["num-no-slash-dates"],
  "tier": "never",
  "level": "error",
  "group": "numbers",
  "message": "Write the date “11/04/2026” with the month in full, such as September 15, 2026, or in the ISO form, such as 2026-09-15, where a machine reads it.",
  "match": "11/04/2026",
  "span": { "index": 275, "length": 10, "line": 5, "column": 89 },
  "link": "https://watership.ca/style-guide/numbers-dates-and-units/#num-no-slash-dates"
}
```

Read it from the top:

- `rule_ids` names the rule the text breaks: `num-no-slash-dates`.
- `tier` is `never`, the strongest tier, so a review reports it first. The `level` is `error` for the same reason.
- `match` and `span` show where it is: the text `11/04/2026`, on line 5, column 89.
- `message` says what to change.

Now find the finding for `Please`. Its tier is `avoid` and its level is `warning`: worth fixing, but a writer can keep it with a reason.

</Step>
<Step>

## Look up the rule [#look-up-the-rule]

A finding gives you a rule id. To get the rule itself, pass the id to `GET /v1/rules/{rule_id}`. Look up the rule behind the `Please` finding:

```sh
curl http://127.0.0.1:4010/v1/rules/term-please \
  -H "Authorization: Bearer wsk_test_tutorial"
```

The response has the rule's guidance in `body`, and an example of the fix:

```json
{
  "id": "term-please",
  "name": "Please in instructions",
  "guide": "style-guide",
  "tier": "avoid",
  "check": "mechanical",
  "automated": true,
  "body": "**Don’t write “please” in documentation or interface text.** An instruction is not a favor, ...",
  "examples": [
    {
      "instead": "Please select Save to keep your changes.",
      "write": "Select Save to keep your changes."
    }
  ]
}
```

This is how the API works throughout. It tells you which rule applies and where, and the rule tells you why. It doesn't rewrite your text.

</Step>
<Step>

## Check the draft from a script [#check-the-draft-from-a-script]

Save the draft as `draft.md`, then save this script beside it. It reads the file, checks it, and prints one line per finding.

<Tabs items={['JavaScript', 'Python']}>
<Tab value="JavaScript">

```js title="check-draft.mjs"
import { readFile } from 'node:fs/promises';

const API_URL = process.env.WATERSHIP_API_URL ?? 'http://127.0.0.1:4010';
const API_KEY = process.env.WATERSHIP_API_KEY ?? 'wsk_test_tutorial';

const text = await readFile('draft.md', 'utf8');

const response = await fetch(`${API_URL}/v1/checks`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ text, format: 'markdown' }),
});

if (!response.ok) {
  const problem = await response.json();
  throw new Error(`${problem.status} ${problem.title}: ${problem.detail}`);
}

const result = await response.json();
const { error, warning, suggestion } = result.counts;
console.log(`Release ${result.release}: ${error} error, ${warning} warnings, ${suggestion} suggestions\n`);

for (const finding of result.findings) {
  const where = `${finding.span.line}:${finding.span.column}`.padEnd(6);
  console.log(`${where} ${finding.level.padEnd(10)} ${finding.rule_ids.join(', ').padEnd(28)} ${finding.message}`);
}
```

Run it:

```sh
node check-draft.mjs
```

</Tab>
<Tab value="Python">

```python title="check_draft.py"
import json
import os
import urllib.error
import urllib.request

API_URL = os.environ.get("WATERSHIP_API_URL", "http://127.0.0.1:4010")
API_KEY = os.environ.get("WATERSHIP_API_KEY", "wsk_test_tutorial")

with open("draft.md", encoding="utf-8") as f:
    text = f.read()

request = urllib.request.Request(
    f"{API_URL}/v1/checks",
    data=json.dumps({"text": text, "format": "markdown"}).encode("utf-8"),
    headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
    method="POST",
)

try:
    with urllib.request.urlopen(request) as response:
        result = json.load(response)
except urllib.error.HTTPError as e:
    problem = json.load(e)
    raise SystemExit(f"{problem['status']} {problem['title']}: {problem['detail']}")

counts = result["counts"]
print(f"Release {result['release']}: {counts['error']} error, {counts['warning']} warnings, {counts['suggestion']} suggestions\n")

for finding in result["findings"]:
    where = f"{finding['span']['line']}:{finding['span']['column']}"
    print(f"{where:<6} {finding['level']:<10} {', '.join(finding['rule_ids']):<28} {finding['message']}")
```

Run it:

```sh
python check_draft.py
```

</Tab>
</Tabs>

The output lists every finding in the order it appears in the draft:

```txt
Release 0.3.3: 1 error, 8 warnings, 2 suggestions

1:3    warning    cap-sentence-case-headings   Use sentence case for headings: “Getting Started With” looks like title case.
3:1    warning    floor-importance-flagging    Cut “It's important to note”; if it matters, say it.
3:37   warning    incl-no-simply               Delete “easily”; the instruction reads the same without it.
3:44   warning    term-use, floor-banned-words Use “use” instead of “utilize”.
3:72   warning    term-lets-you                Use “lets you” instead of “allows you to”.
3:97   warning    floor-banned-words           “seamless” is on the slop guard’s banned list.
3:125  warning    term-please                  Don’t write “please” in documentation or interface text.
3:132  warning    ui-select-verb               Use “select” instead of “click”.
5:28   suggestion punct-semicolon              Prefer a period to a semicolon.
5:30   suggestion voice-contractions           Write “it is rare” with a contraction: “it’s”, “you’re”, or “you’ll”.
5:89   error      num-no-slash-dates           Write the date “11/04/2026” with the month in full, such as September 15, 2026, or in the ISO form, such as 2026-09-15, where a machine reads it.
```

</Step>
</Steps>

## What you did [#what-you-did]

You started a mock of the API, saw how it rejects a request without a key, and checked a draft. You read a finding's rule id, tier, and position, and used the rule id to get the rule. Then you ran the same check from a script.

Here's the draft with every finding fixed, for comparison:

```md
# Get started with exports

Export a copy of your data from the export tool. Select **Export** to begin.

Exports finish within a day, and they rarely fail. The next maintenance window is November 4, 2026.
```

The fix reads `11/04/2026` as November 4. A reader in another country could read it as April 11, which is why the rule is never-tier: only the writer knows which date they meant.

## Next steps [#next-steps]

- To block a pull request on errors, follow [Check a pull request in CI](https://watership.ca/api-docs/docs/tasks/check-a-pull-request).
- To see every field a finding can have, read [The finding object](https://watership.ca/api-docs/docs/reference/finding).
- To understand why the API reports rule ids and leaves the rewriting to you, read [Why findings carry rule ids](https://watership.ca/api-docs/docs/concepts/rule-ids-not-rewrites).
