# API Overview & Conventions

> Base URLs, authentication headers, payload conventions, response structures, and standard error handling.

- **Category:** REST API
- **Canonical Guide:** https://pottr.tangble.com/docs/api-overview

---

>
Base URLs, authentication headers, payload conventions, response structures, and standard error handling.

## Base Endpoint

All Pottr REST routes are anchored under the following base URL:

https://your-domain.com/wp-json/pottr/v1

## Authentication Header Model

Pottr supports three primary authentication patterns depending on your client environment:

<table class="docs-table">
<thead>
<tr>
<th>Pattern</th>
<th>Headers</th>
<th>Use Case</th>
</tr>
</thead>
<tbody>
<tr>
<td>**Dual-Header (Recommended)**</td>
<td>
`Authorization: Bearer pk_live_...`<br />
`X-Pottr-User-Token: <JWT>`
</td>
<td>Single-Page Apps, mobile apps, and Jamstack clients. Authenticates the site gateway and the end-user identity simultaneously.</td>
</tr>
<tr>
<td>**Secret Key**</td>
<td>`Authorization: Bearer sk_live_...`</td>
<td>Server-to-server microservices, Node/Python backends, CI/CD scripts. Full administrative bypass.</td>
</tr>
<tr>
<td>**User JWT Only**</td>
<td>`Authorization: Bearer <JWT>`</td>
<td>Direct user authentication endpoints and user-scoped data calls.</td>
</tr>
</tbody>
</table>

## Standard Error Response Format

When an error occurs, Pottr returns a normalized JSON error payload accompanied by the relevant HTTP status code:

**File: `401 Unauthorized Response`**

```text
{
  "error": true,
  "code": "invalid_api_key",
  "message": "The provided API key is invalid or revoked."
}
```

## Common Error Codes

<table class="docs-table">
<thead>
<tr>
<th>HTTP Status</th>
<th>Error Code</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>`400`</td>
<td>`missing_required` / `unknown_field` / `invalid_field` / `validation_failed`</td>
<td>A required field is missing or empty, the body has a key that is not in the schema, or a value fails its field type or validation rule.</td>
</tr>
<tr>
<td>`401`</td>
<td>`invalid_api_key` / `unauthorized` / `invalid_token`</td>
<td>Missing or invalid API key, or a missing, invalid or expired user token.</td>
</tr>
<tr>
<td>`403`</td>
<td>`insufficient_key_scope` / `forbidden` / `entry_limit_reached` / `collection_limit_reached`</td>
<td>A public key on a secret-only route, another user's entry, or a plan limit reached.</td>
</tr>
<tr>
<td>`404`</td>
<td>`collection_not_found` / `not_found`</td>
<td>The collection slug or entry ID does not exist.</td>
</tr>
<tr>
<td>`409`</td>
<td>`concurrency_conflict` / `email_exists`</td>
<td>The entry changed since you loaded it, or the email is already registered in that app.</td>
</tr>
<tr>
<td>`429`</td>
<td>`api_limit_exceeded` / `rate_limited` / `rate_limit_exceeded`</td>
<td>Your monthly API-call quota is used up (writes pause first), or a rate limit was hit. Check the `Retry-After` header when present.</td>
</tr>
</tbody>
</table>

## Response Formats

By default, list endpoints return flattened entries (`id` as a string, `created_at` and your fields), and create, get and update return the stored entry. To get one uniform shape everywhere, opt in to the standard envelope with `?format=standard` or the header `Accept: application/vnd.pottr.v1+json`:

**File: `Standard format`**

```json
{
  "data": {
    "id": "87",
    "collection": "tasks",
    "attributes": { "title": "Ship documentation", "completed": false },
    "created_at": "2026-11-18 10:00:00",
    "updated_at": "2026-11-18 10:05:00"
  }
}
```

## Other Headers

<ul>
<li>`X-Pottr-App`: names the app when one site hosts several, so app-user tokens and tables resolve to the right app.</li>
<li>Live event streams (`/events`) accept the key and token as query parameters because browsers cannot set headers on `EventSource`. Secret keys are never accepted in a query string.</li>
</ul>
