# Nightmail API

Send, receive and reply to email on your own domains. 202 means queued, not delivered.

- [Interactive documentation](/docs)
- [OpenAPI 3.1 JSON](/openapi.json)
- [Agent index](/llms.txt)
- TypeScript package: `@nightmail/sdk`

[API index](/docs.md) · [Rules reference](/docs/tags/rules.md)

## Get rule version

`GET /v1/rules/version`

Read the rules and routes version, or wait for it to change. Without after, returns the current version at once. With after (and endpoints, to include endpoint changes), waits up to wait seconds for a rule, route or endpoint save and returns as soon as one commits, with who saved it. The dashboard keeps one of these open while you edit rules so an agent’s saves appear live. Each waited 2.5 seconds counts as one request against the credential’s per-minute budget.

Operation ID: `getRuleVersion`

Permission: Needs Receiving rules: read on the whole workspace. A person needs to be an owner or admin.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `after` | query | integer or null | no | The version you have. The call waits until the version differs from it. |
| `endpoints` | query | string | no | The endpoints marker from the last response: also wait for an endpoint to be created, changed or deleted. |
| `wait` | query | integer or null | no | Seconds to wait for a change (0–25). Ignored without after or endpoints. |


### TypeScript SDK

```ts
import { createClient } from '@nightmail/sdk/client';
import { getRuleVersion } from '@nightmail/sdk';

const client = createClient({
  baseUrl: 'https://nightmail.dev',
  auth: scheme => scheme.scheme === 'bearer'
    ? process.env.NIGHTMAIL_API_KEY
    : undefined,
});

const result = await getRuleVersion({
  client,
  throwOnError: true,
});

console.log(result.data);
```

### cURL

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/rules/version' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY"
```

### Responses

| Status | Description | Schema |
| --- | --- | --- |
| `200` | Success | object |
| `400`, `401`, `403`, `404`, `409`, `413`, `422`, `429`, `500`, `503` | Request failed; use error.code and requestId to diagnose. | object |

#### 200: Success

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `version` | integer | yes | The routing version. Routes and rules share it, and it is the If-Match for saving either. |
| `endpoints` | string | yes | Marks the latest endpoint change seen. Pass it back as endpoints to wait for the next one. |
| `changed` | boolean | yes | version or endpoints moved past what you passed as after and endpoints. |
| `actor` | object or null | yes | Who made the change returned: the save behind version, or else the latest endpoint change. Null when nothing changed. |
| `actor.type` | string | yes | member is a person in the dashboard, api_key an API key, mcp an MCP client (or a temporary token it made). |
| `actor.name` | string or null | yes | The member’s name, the API key’s name or the MCP client and its profile label; null when it is gone. Never an email address. |
| `actor.self` | boolean | yes | The credential making this request made the change (another tab, say). |

#### 400, 401, 403, 404, 409, 413, 422, 429, 500, 503: Request failed; use error.code and requestId to diagnose.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | object | yes |  |
| `error.code` | string | yes |  |
| `error.message` | string | yes |  |
| `error.requestId` | string | yes |  |
| `error.field` | string | no |  |
| `error.retryable` | boolean | yes |  |
| `error.resetAt` | string | no | Next capacity change for a Hosted rolling send limit. |
| `error.details` | object[] | no | Every problem found, when there is more than one part, such as rule diagnostics with rule, line, column, message and hint, or a measurement, such as CONTENT_TOO_LARGE_TO_SCREEN with screenedBytes and limitBytes (and index in a batch). |
| `error.required` | object | no | On a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same. |
