# Post findings to GitHub as review comments.

> An explicit action, never automatic: posts one GitHub review (`COMMENT`, never an approval or a request for changes) on `headSha`, with a comment on the line for each finding that names one and the rest in the review's body.
> https://koi.dog/docs/api/pull-requests/post-pull-request-findings/

`POST /api/v1/pull-requests/{id}/findings/post` · Scope: `approve`

Only findings written at `headSha` (`409 stale_findings` otherwise). Findings already posted are not sent again. Uses the server's own GitHub access; no agent holds it. Records who posted. The timeline records the key ID, action and outcome.

## Path parameters.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | The pull request's id. |

## Headers.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Retry the same request with the same key. [Retry rules](https://koi.dog/docs/api/#retries). |

## Body.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `headSha` | `string` | yes | The head commit the findings are posted on; refused when the pull request has moved since. Matches `^[0-9a-f]{40}$`. |
| `findingIds` | `array` | no | The findings to post. Default: every finding at `headSha` not posted yet. 1 to 50 items. |
| `body` | `string` | no | Text for the review's own body. At most 4000 characters. |

## Response.

200 OK · JSON object

- **422 validation_failed**: Each schema error appears in `details`.

## Request.

```sh
curl -X POST "https://api.koi.dog/api/v1/pull-requests/$ID/findings/post" \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{
      "headSha": "<head commit sha>"
    }'
```

```js
const res = await fetch(`https://api.koi.dog/api/v1/pull-requests/${process.env.ID}/findings/post`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    headSha: "<head commit sha>",
  }),
});
console.log(await res.json());
```

```python
import os
import uuid

import requests

r = requests.post(
    f"https://api.koi.dog/api/v1/pull-requests/{os.environ['ID']}/findings/post",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "headSha": "<head commit sha>",
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "posted": 0,
  "alreadyPosted": 0,
  "reviewUrl": "string",
  "findings": []
}
```
