# Requests

> The JSON:API format, headers, filtering, sorting, pagination, includes, ETags and idempotency keys.

## Format

Every request and response under `/v1` is [JSON:API 1.1](https://jsonapi.org/format/1.1/). Send these headers:

| Header            | Value                          | When                           |
| ----------------- | ------------------------------ | ------------------------------ |
| `Authorization`   | `Bearer <key or token>`        | Always                         |
| `Accept`          | `application/vnd.api+json`     | Always                         |
| `Content-Type`    | `application/vnd.api+json`     | With a request body            |
| `Idempotency-Key` | A unique value, such as a UUID | On the creates that require it |
| `If-Match`        | The resource's `ETag`          | On updates that require it     |

A wrong `Accept` returns `406`; a wrong `Content-Type` returns `415`.

## Resources

A resource has a `type`, an `id`, `attributes` and `relationships`. Member names are camelCase. A resource's `type` can differ from its route: `POST /v1/screenings` creates `screeningChecks`.

```json
{
  "data": {
    "type": "verifications",
    "id": "0196d62a-4c1e-7d2b-9f3a-6b1c2d3e4f50",
    "attributes": {
      "kind": "identityDocument",
      "status": "verified",
      "assurance": "registryVerified",
      "timestamps": {
        "created": "2026-11-27T09:14:03.512Z",
        "completed": "2026-11-27T09:15:41.078Z"
      }
    },
    "relationships": {
      "subject": {
        "data": {
          "type": "people",
          "id": "0196d629-118b-7c3f-a049-dbb513d3ee95"
        }
      }
    }
  }
}
```

- Lifecycle instants live in `attributes.timestamps`, in UTC with millisecond precision.
- Calendar dates, such as a date of birth, are plain `YYYY-MM-DD` strings.
- IDs are UUIDs generated by Aqoonsi. Store them as strings.
- One-time secrets (API keys, tokens, signing secrets) appear once, in `meta.secret`.

## Creating and updating

Send attributes in `data.attributes` and links to other resources in `data.relationships`. On an update (`PATCH`), include `data.id` and only the members you change.

```bash
curl -X PATCH https://api.aqoon.si/v1/people/$PERSON_ID \
  -H "Authorization: Bearer $AQOONSI_KEY" \
  -H "Accept: application/vnd.api+json" \
  -H "Content-Type: application/vnd.api+json" \
  -H "If-Match: $ETAG" \
  -d '{"data":{"type":"people","id":"'"$PERSON_ID"'","attributes":{"middleName":"Cali"}}}'
```

## Filtering and sorting

Collections accept `filter[...]` parameters and `sort`. Each endpoint documents the filters it supports; an unsupported one returns `400`. Separate several values with commas. Prefix a sort field with `-` for descending order.

```bash
curl --globoff "https://api.aqoon.si/v1/verifications?filter[status]=verified,failed&sort=-created" \
  -H "Authorization: Bearer $AQOONSI_KEY" -H "Accept: application/vnd.api+json"
```

## Pagination

Collections return 25 resources by default. Set `page[size]` up to 100. Follow `links.next` until it is absent or `null`; do not build page links yourself.

```bash
next="https://api.aqoon.si/v1/people?page[size]=100"
while [ -n "$next" ] && [ "$next" != "null" ]; do
  page=$(curl --globoff -s "$next" -H "Authorization: Bearer $AQOONSI_KEY" -H "Accept: application/vnd.api+json")
  printf '%s' "$page" | jq -c '.data[]'
  next=$(printf '%s' "$page" | jq -r '.links.next // empty')
done
```

## Sparse fieldsets and includes

Request only the attributes you need with `fields[type]`, and related resources in the same response with `include`:

```bash
curl --globoff "https://api.aqoon.si/v1/cases?include=subject&fields[cases]=number,status,priority" \
  -H "Authorization: Bearer $AQOONSI_KEY" -H "Accept: application/vnd.api+json"
```

An include needs the read scope of the included type as well. `include=subject` on a case needs `people:read` for a person, or `businesses:read` for a business; without it the request returns `403` naming the missing scope, with `source.parameter` set to `include`. The one exception is who acted: `include=reviewer` on match reviews, `include=user` on overrides and `include=actor` on the audit log bring people and API keys by name only, with no further scope.

## ETags and If-Match

A single resource is returned with an `ETag` header. The same value is in the resource's `meta.etag` wherever it appears, in lists and in `included` too, so you can update a resource you listed without reading it again. Where an endpoint protects updates, send that value as `If-Match`:

- a stale `If-Match` returns `412`: fetch the resource again and reapply your change;
- a missing `If-Match` where one is required returns `428`.

## Idempotency keys

Creates that start work, such as verifications, sessions, screenings and assessments, require an `Idempotency-Key` header. Use one new key per logical operation, and reuse the same key and body when you retry it.

- A retry with the same key returns the original response, and nothing runs twice. Responses are kept for 24 hours.
- A key reused with a different body returns `422 idempotency.keyReused`.
- A retry while the first request is still running returns `409 idempotency.inFlight`: wait and retry.
- A replayed response that contained a one-time secret carries `meta.secretAlreadyIssued` instead of the secret.

## Request IDs

Every response has an `X-Request-ID` header. Log it, and quote it when you contact support.
