# Concepts

> How the packeroo API signs in, makes retries safe, reports errors and limits requests. Token prefixes, idempotency keys, problem answers after RFC 9457, rate limits, User-Agent, times and versions.

These rules hold for every public operation. What is described here is built; what is planned is marked as such.

## Addresses

| Environment | Base address | Tokens |
| --- | --- | --- |
| Live | `https://api.packeroo.com/api/v1` | `pkd_live_…` |
| Sandbox | `https://api.qm.packeroo.com/api/v1` | `pkd_test_…` |

The sandbox is the demo environment of packeroo. It can be reset; keep nothing there you want to keep. In the sandbox a device pairs itself with `POST /sandbox/device-pairings/confirm` at a test table of its own, without anyone entering the code in the app; see the [quickstart](https://developers.packeroo.com/en/quickstart/).

## Authentication and token prefixes

A device signs in with its token in the header:

```http
Authorization: Bearer pkd_live_7Hq2xV9pLm3RtY6wQz8NbC4kDf1Gs5Je0aB3cD
```

The token is a random string, not a JWT: it carries no data, and once the device is unpaired it stops working at once. packeroo stores only its SHA-256 hash and shows it exactly once, in the answer to `POST /device-pairings`.

A token is 47 characters long: a prefix, 32 random characters and a checksum of 6. The prefix tells kind and environment. The checksum lets secret scanners recognize a leaked token, and the API refuses a mistyped one without looking it up.

| Prefix | Kind | State |
| --- | --- | --- |
| `pkd_live_`, `pkd_test_` | device at a table | available |
| `pko_live_`, `pko_test_` | organization key for intranets, dashboards, chat bots | planned |
| `pkp_live_`, `pkp_test_` | personal token | planned |

Tokens belong on devices and servers, never in a web page. The API accepts requests from a browser only from the packeroo app.

## Scopes

`GET /device` names in `scopes` what the token may do. For a device token this is a fixed set: `leagues:read`, `standings:read`, `matches:read`, `matches:write`, `matches:live`. It includes scopes for operations that are planned; those take effect only once the operations exist. Today the token is good for `GET /device`. When an operation is added, a paired device does not need to be paired again: its token has the scopes already.

## Idempotency key

Every write (`POST`, `PUT`, `PATCH`, `DELETE`) carries the header `Idempotency-Key` with a UUID or ULID. Make a new key for every new action, and send the same one when you repeat a request, for example after a network error.

- The same request with the same key gets the first answer again, with the header `Idempotent-Replayed: true`, and has no second effect. Only successful answers are kept, for 48 hours.
- No key, or one that is neither UUID nor ULID: `400` `idempotency_key_required`.
- The same key with a different request: `422` `idempotency_key_reused`.
- The first request is still running: `409` `request_in_progress`. Wait a moment and repeat it with the same key.
- An answer holding a secret, such as the token of `POST /device-pairings`, is never kept. A repeat runs again there and gives a new code with a new token.

## Error answers

Every error comes as a problem after [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457) with the content type `application/problem+json`:

```json
{
  "type": "https://api.packeroo.com/problems/user-agent-required",
  "title": "User-Agent required",
  "status": 400,
  "detail": "The device does not name itself. Every request needs a User-Agent, such as Kickertisch/1.2.",
  "code": "user_agent_required",
  "correlation_id": "01JD7R4X2Y3Z4A5B6C7D8E9F0G"
}
```

- **`code`** is fixed. Branch only on `code` in your program.
- **`title`** is a short English summary, the same for every occurrence of a code.
- **`detail`** says what happened and what to do, in the language of `Accept-Language`: `de` or `en`, German without the header. It is meant for display, not for parsing.
- **`correlation_id`** is also in the header `X-Correlation-Id` of every answer. Name it when you write to us about an error.
- **`errors`** comes only with `validation_failed`: the messages per field.

### Codes of the public operations

| Code | Status | Meaning |
| --- | --- | --- |
| `user_agent_required` | 400 | The request has no `User-Agent`. |
| `idempotency_key_required` | 400 | The write has no valid `Idempotency-Key`. |
| `bad_request` | 400 | The request cannot be read, for example no valid UTF-8. |
| `unauthenticated` | 401 | No valid token: not paired yet, unpaired, from the other environment, or table devices are switched off. |
| `not_found` | 404 | The operation does not exist here, such as `POST /sandbox/device-pairings/confirm` outside the sandbox. |
| `device_already_paired` | 409 | The device asking for a code is paired already. It keeps its token. |
| `table_devices_off` | 409 | Table devices are switched off; no device pairs. |
| `request_in_progress` | 409 | A request with the same idempotency key is still running. |
| `idempotency_key_reused` | 422 | The idempotency key belongs to another request already. |
| `validation_failed` | 422 | A field is invalid; `errors` names it. |
| `rate_limited` | 429 | Too many requests; `Retry-After` gives the wait in seconds. |
| `server_error` | 500 | An error at packeroo. The cause is in our log under the `correlation_id`. |
| `unavailable` | 503 | packeroo cannot be reached for a moment. Try again later. |

## Rate limits

| What | Limit |
| --- | --- |
| `POST /device-pairings` | 60 a minute per IP address |
| `POST /sandbox/device-pairings/confirm` | 10 an hour and 20 new test tables a day per IP address (IPv6 per /48) |
| `GET /device` | 120 a minute per device |

The limit for codes counts per IP address, the one for `GET /device` per device. An example: in a hall, 40 tables sit behind one address. After a power cut all of them ask for a code at once, which is 40 of 60 `POST` a minute. Then every device asks `GET /device` every five seconds, 12 of 120 per device; the 40 devices do not add up there. With more than 60 tables behind one address, the rest get `429` with `Retry-After` and ask again after it; the examples of the guide do that by themselves. Whoever goes over a limit gets `429` with `rate_limited` and the header `Retry-After` in seconds. Wait that long before you try again.

Planned: the headers `RateLimit` and `RateLimit-Policy` after the IETF draft on every answer, and limits of their own for goals and organization keys once those operations exist.

## User-Agent

Every request of a device names its product and firmware in the `User-Agent`, such as `Kickertisch/1.2` or `Kickertisch-ESP32/0.9.3`. That tells a misbehaving device apart from the others in the logs without anyone looking at its token. Without a `User-Agent` the API answers `400` with `user_agent_required`.

## Times

Times come in ISO 8601 and always in UTC, with a `Z` at the end: `2026-11-22T14:15:00Z`. Show them in the time zone of the location; `GET /device` names it in `location.time_zone`, such as `Europe/Berlin`. IDs are ULIDs, 26 characters, sortable by time.

## Versioning

The version is in the path: `/api/v1`. Within `v1` only additions come: new operations, new fields, new error codes. Write your program so that unknown fields in an answer break nothing. What would break existing programs goes into a new version `v2`.

Planned: what goes away is announced with the headers `Deprecation` and `Sunset` (RFC 8594), at least six months ahead. For operations of devices, whose firmware stays in the field for years, twelve months ahead and not before 24 months after their release.

New operations and changes are in the [changelog](https://developers.packeroo.com/en/changelog/), also as an RSS feed.
