# Conventions

How every endpoint and MCP tool behaves: requests and responses, errors, paging, rate limits and versioning.

## Requests and responses

- JSON bodies, `Content-Type: application/json`, at most 1,000,000 bytes.
- Field names are camelCase. **Unknown fields are refused** (`422 invalid_field`), so a typo fails loudly instead of being ignored.
- Types are strict: `true` is not `1`, and `"2450"` is not a number. Dates are `YYYY-MM-DD`; times are ISO 8601 in UTC with milliseconds (`2026-11-04T09:15:02.311Z`).
- Responses carry `Cache-Control: no-store`.
- A create answers `201` with a `Location` header; a delete with no body to return answers `204`.

## Errors

Every error has the same shape:

```json
{ "error": { "code": "invalid_field", "message": "answers[0].propertyIds contains 99, which is not one of your properties", "field": "answers[0].propertyIds" } }
```

`field` is present when one field or query parameter is to blame. `message` is written to be shown to a person, or acted on by an agent.

| Status | Code | Meaning |
|--------|------|---------|
| 400 | `invalid_json` | The body is not a JSON object |
| 401 | `missing_api_key`, `invalid_api_key` | See [authentication](https://docs.wayline.com/authentication.md) |
| 403 | `managed_guardrail` | A guardrail Wayline maintains cannot be changed or deleted |
| 404 | `not_found` | No such record in your organization, or no such endpoint |
| 405 | `method_not_allowed` | The endpoint exists but not with that method |
| 409 | `duplicate_external_id` | Another listing already has that `externalId` |
| 409 | `duplicate_question` | That question is already in your knowledge base (case and spacing are ignored) |
| 409 | `last_answer` | A question must keep at least one answer: delete the question instead |
| 409 | `import_in_progress` | An import is already running; retry after `Retry-After` seconds |
| 413 | `body_too_large` | The body is over 1,000,000 bytes |
| 422 | `invalid_field` | A body field is missing, the wrong type or not allowed |
| 422 | `invalid_parameter` | A query parameter is wrong |
| 422 | `invalid_scope` | Answers or a guardrail scoped in a way that cannot be resolved (see [knowledge](https://docs.wayline.com/knowledge.md#scope)) |
| 429 | `rate_limited` | Too many requests; wait `Retry-After` seconds |
| 500 | `internal_error` | Something failed on our side; retry |

## Paging

Lists return one page at a time, in ascending `id` order:

```json
{ "data": [ … ], "nextCursor": "aWQ6MTIz" }
```

- `limit`: 1 to 100, default 50.
- `cursor`: pass `nextCursor` from the previous page to get the next one. It is opaque; don't build your own.
- `nextCursor` is `null` on the last page.

Records created while you page appear on a later page (their ids are higher); filters such as `updated_since` let a sync pick up only what changed.

## Rate limits

- 120 requests per minute per API key, counting both REST requests and [MCP](https://docs.wayline.com/mcp.md) tool calls, and 120 tool calls per minute per signed-in MCP connection.
- 600 requests per minute per IP address across the whole API, and separately across the MCP server.

Over either, the API answers `429 rate_limited` with a `Retry-After` header in seconds. Back off for at least that long.

## Versioning

The version is in the path (`/v1`). Within `v1`, fields and endpoints may be added; nothing is removed or changes meaning. Ignore response fields you don't use, so an added field never breaks you.
