# API: Data hygiene

| Method | Path | What it does | Scope |
|---|---|---|---|
| POST | `/v1/hygiene/audit` | Run the hygiene agent now: it inspects the CRM and lists issues ranked by pipeline affected, each with a proposed fix (nothing changes until a person approves) | `settings:write` |
| GET | `/v1/hygiene/issues` | Issues the hygiene agent found, highest impact first | `records:read` |
| POST | `/v1/hygiene/issues/:id/apply` | Approve and apply an issue's fix as you (merges, reassignments, field fixes, follow-up tasks, archiving an unused field). The result is re-read to verify, and can be reverted except merges. (web app only) | `records:write` |
| POST | `/v1/hygiene/issues/:id/dismiss` | Dismiss an issue (not a problem, or handled by hand) (web app only) | `records:write` |
| POST | `/v1/hygiene/issues/:id/revert` | Undo an applied fix (values changed since are left alone and listed) (web app only) | `records:write` |
| GET | `/v1/hygiene/rules` | Monitoring rules: checks re-run nightly; the chosen person gets an email when new issues appear | `records:read` |
| PUT | `/v1/hygiene/rules` | Choose which checks run nightly and who's told (owner) | `settings:write` |

## Examples

### POST /v1/hygiene/audit

Run the hygiene agent now: it inspects the CRM and lists issues ranked by pipeline affected, each with a proposed fix (nothing changes until a person approves)

```bash
curl -s -X POST "https://api.closefinch.com/v1/hygiene/audit" \
  -H "Authorization: Bearer $RA_API_KEY" \
  -H "content-type: application/json" \
  -d '{}'
```

```js
const res = await fetch(`https://api.closefinch.com/v1/hygiene/audit`, {
  method: "POST",
  headers: { authorization: `Bearer ${process.env.RA_API_KEY}`, "content-type": "application/json" },
  body: JSON.stringify({}), // fields: see the OpenAPI schema
});
const data = await res.json();
```

### GET /v1/hygiene/issues

Issues the hygiene agent found, highest impact first

```bash
curl -s "https://api.closefinch.com/v1/hygiene/issues" \
  -H "Authorization: Bearer $RA_API_KEY"
```

```js
const res = await fetch(`https://api.closefinch.com/v1/hygiene/issues`, {
  method: "GET",
  headers: { authorization: `Bearer ${process.env.RA_API_KEY}` },
});
const data = await res.json();
```

### GET /v1/hygiene/rules

Monitoring rules: checks re-run nightly; the chosen person gets an email when new issues appear

```bash
curl -s "https://api.closefinch.com/v1/hygiene/rules" \
  -H "Authorization: Bearer $RA_API_KEY"
```

```js
const res = await fetch(`https://api.closefinch.com/v1/hygiene/rules`, {
  method: "GET",
  headers: { authorization: `Bearer ${process.env.RA_API_KEY}` },
});
const data = await res.json();
```

### PUT /v1/hygiene/rules

Choose which checks run nightly and who's told (owner)

```bash
curl -s -X PUT "https://api.closefinch.com/v1/hygiene/rules" \
  -H "Authorization: Bearer $RA_API_KEY" \
  -H "content-type: application/json" \
  -d '{}'
```

```js
const res = await fetch(`https://api.closefinch.com/v1/hygiene/rules`, {
  method: "PUT",
  headers: { authorization: `Bearer ${process.env.RA_API_KEY}`, "content-type": "application/json" },
  body: JSON.stringify({}), // fields: see the OpenAPI schema
});
const data = await res.json();
```

Request and response schemas: [https://www.closefinch.com/openapi.json](https://www.closefinch.com/openapi.json). All resources: [API reference](https://www.closefinch.com/docs/api).
