# Auth, Headers, Pagination, And Errors

## Base URL

Use the canonical implementation URL:

```bash
export CASE_BASE_URL="https://platform3-andymontgomery-9773s-projects.vercel.app/case/1edtech/implementation/api"
```

Do not call the underlying Vercel hash deploy URL in app code or reports unless a reviewer explicitly asks you to compare deploy routing. The canonical URL is the customer contract.

## Demo Token

```bash
export CASE_TOKEN="$(curl -s -X POST "$CASE_BASE_URL/dev/mint?tenantId=demo" | jq -r '.token')"
```

`/dev/mint?tenantId=demo` is public and demo-only. A non-demo tenant token must come from an operator or the loop driver.

## Required Headers

Read calls:

```bash
-H "Authorization: Bearer $CASE_TOKEN"
```

Create/import/write calls:

```bash
-H "Authorization: Bearer $CASE_TOKEN"
-H "Content-Type: application/json"
-H "Idempotency-Key: <unique-key>"
```

PUT, PATCH, and DELETE calls:

```bash
-H "If-Match: <current-validator>"
```

Use the `ETag` from a detail GET or create response as the first current validator. After a successful PUT or PATCH, use `X-Case-ETag` for the next write because the Vercel edge-compatible `ETag` can echo the submitted value.

## Pagination

CASE list routes use offset paging. If a response includes `links.next`, follow its path and query on `CASE_BASE_URL`.

```bash
NEXT="$(jq -r '.links.next // empty' /tmp/case-page-1.json)"
NEXT_PATH="$(printf '%s' "$NEXT" | sed -E 's#^https?://[^/]+##; s#^/api/#/#')"
[ -n "$NEXT_PATH" ] && curl -s "$CASE_BASE_URL$NEXT_PATH" -H "Authorization: Bearer $CASE_TOKEN"
```

Do not switch origins while paging.

## Error Handling

The surface returns RFC 7807 Problem Details with `case:*` codes, `requestId`, and `traceId`.

Do not keep a local problem-code table. For authoritative details, read the customer website Errors section and the live `/problems` endpoint.
