---
title: Create an access grant
description: "Give a buyer, repairer or recycler access to restricted passport data. The raw pa_ token is returned once, never stored. Authority roles: dashboard only."
canonical: "https://www.tracepass.eu/docs/create-access-grant"
locale: en
source: "https://www.tracepass.eu/docs/create-access-grant"
---

# Create an access grant

> Give a buyer, repairer or recycler access to restricted passport data. The raw pa_ token is returned once, never stored. Authority roles: dashboard only.

```http
POST /api/v1/access-grants
```

Give a recipient access to the restricted part of your passports, with the same rules as the dashboard: the role decides which data points the grant shows, a purchaser grant names the passports it covers and ends when the battery changes hands, and a company has at most 50 active grants.

**The raw `pa_` token is returned once, in this `201`, and never again.** Only a hash is stored. Hand it to the recipient straight away and do not log it. An idempotent replay (same `Idempotency-Key`, same body) returns the grant without the token and with `tokenDelivered: true`, so the idempotency store never holds a credential. If the token is lost, revoke the grant and create a new one. The `notice` field says the same in the response.

**Authority roles stay in the dashboard.** `market_surveillance`, `notified_body`, `commission` and `customs`, and the `authority` tier on the `other` role, answer `400 role_dashboard_only`. The access log records which API key or app created the grant.

**Who may call it.** An API key only when its owner switched on "May manage access grants" for that key on the Developer page (off by default; otherwise `403 access_grants_not_enabled`). An OAuth token needs the `access_grants:write` scope and a user who is an admin or owner. Needs a paying account. Counts as one v1 write.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Authorization` | header | string | yes | `Bearer <token>` — either a `tp_` API key (Developer → API Keys; simplest, for server-to-server) or an OAuth 2.0 access token (Developer → OAuth Apps; for user-authorized apps, scoped + revocable). The Authentication page has the full OAuth flow and scope list. |
| `Idempotency-Key` | header | string | no | UUID v4. |
| `role` | body | string | yes | The recipient's role: `repairer`, `remanufacturer`, `repurposer`, `recycler`, `waste_treatment`, `training_centre`, `purchaser`, `purchaser_agent`, `elv_treatment`, `weee_treatment` or `other`. The four authority roles are refused. |
| `label` | body | string (1-120 chars) | yes | Who the grant is for, as you want to see it. |
| `scope` | body | object | no | `{ "kind": "company" }`, `{ "kind": "products", "ids": \[...\] }` or `{ "kind": "passports", "ids": \[...\] }` (up to 500 ids, all in your company). A purchaser grant must list passports. |
| `purpose` | body | string (max 500 chars) | no | Why the recipient gets access. |
| `evidence` | body | object | no | `{ type, reference, note? }` where `type` is `register_entry`, `invoice`, `authority_letter`, `contract` or `other`. Recorded, not verified. |
| `expiresInDays` | body | integer \| null (1-1825) | no | Days until expiry. Omit for the role's default (12 months; none for a purchaser, whose grant ends when the battery changes hands). `null` = no expiry. |

## Examples

```bash
curl -sS -X POST https://app.tracepass.eu/api/v1/access-grants \
  -H "Authorization: Bearer tp_REDACTED_xxxxxxxxxxxx" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "role": "purchaser",
  "label": "Buyer GmbH, order 4711",
  "scope": { "kind": "passports", "ids": ["6650a1b2c3d4e5f6a7b8c9d0"] }
}'
```

```typescript
const res = await fetch("https://app.tracepass.eu/api/v1/access-grants", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.TRACEPASS_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    role: "purchaser",
    label: "Buyer GmbH, order 4711",
    scope: { kind: "passports", ids: [passportId] },
  }),
});
const grant = await res.json();
// grant.token is shown once: pass it to the recipient, never log it.
```

```python
import os, uuid, requests
res = requests.post(
    "https://app.tracepass.eu/api/v1/access-grants",
    headers={
        "Authorization": f"Bearer {os.environ['TRACEPASS_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "role": "purchaser",
        "label": "Buyer GmbH, order 4711",
        "scope": {"kind": "passports", "ids": [passport_id]},
    },
)
res.raise_for_status()
grant = res.json()  # grant["token"] is shown once
```

## Responses

### 201 — Created (token shown once)

```json
{
  "id": "6650c1d2e3f4a5b6c7d8e9f0",
  "accessLevel": "restricted",
  "label": "Buyer GmbH, order 4711",
  "role": "purchaser",
  "scope": { "kind": "passports", "ids": ["6650a1b2c3d4e5f6a7b8c9d0"] },
  "purpose": null,
  "evidence": null,
  "state": "active",
  "expiresAt": null,
  "useCount": 0,
  "createdAt": "2026-06-01T09:30:00.000Z",
  "token": "pa_REDACTED_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "notice": "Pass this token to the recipient now. It cannot be shown again: only a hash is stored, and neither the list nor an idempotent replay returns it."
}
```

### 201 — Idempotent replay (no token)

```json
{
  "id": "6650c1d2e3f4a5b6c7d8e9f0",
  "accessLevel": "restricted",
  "label": "Buyer GmbH, order 4711",
  "role": "purchaser",
  "scope": { "kind": "passports", "ids": ["6650a1b2c3d4e5f6a7b8c9d0"] },
  "purpose": null,
  "evidence": null,
  "state": "active",
  "expiresAt": null,
  "useCount": 0,
  "createdAt": "2026-06-01T09:30:00.000Z",
  "tokenDelivered": true,
  "notice": "The token was delivered in the first response to this request and cannot be shown again. Revoke this grant and create a new one if it was lost."
}
```

### 400 — Authority role

```json
{
  "error": "role_dashboard_only",
  "message": "Authority grants (market_surveillance, notified_body, commission, customs, or the authority tier) are created in the dashboard only."
}
```

### 403 — Switch off

```json
{
  "error": "access_grants_not_enabled",
  "message": "This API key may not manage access grants. Its owner can switch on 'May manage access grants' for the key on the Developer page."
}
```

## Related

- [List access grants](https://www.tracepass.eu/docs/list-access-grants.md)
- [Revoke an access grant](https://www.tracepass.eu/docs/revoke-access-grant.md)
