---
title: "Creare un'autorizzazione di accesso"
description: Dai a un acquirente o riciclatore accesso ai dati riservati. Il token pa_ è restituito una sola volta, mai salvato. Autorità solo nella dashboard.
canonical: "https://www.tracepass.eu/it/docs/create-access-grant"
locale: it
source: "https://www.tracepass.eu/it/docs/create-access-grant"
---

# Creare un'autorizzazione di accesso

> Dai a un acquirente o riciclatore accesso ai dati riservati. Il token pa_ è restituito una sola volta, mai salvato. Autorità solo nella dashboard.

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

Date a un destinatario accesso alla parte riservata dei vostri passaporti, con le stesse regole della dashboard: il ruolo decide quali punti dati mostra l'autorizzazione, un'autorizzazione da acquirente indica i passaporti che copre e termina quando la batteria cambia proprietario, e un'azienda ha al massimo 50 autorizzazioni attive.

**Il token `pa_` è restituito una sola volta, in questo `201`, e mai più.** Viene salvato solo un hash. Consegnatelo subito al destinatario e non registratelo nei log. Una ripetizione idempotente (stessa `Idempotency-Key`, stesso corpo) restituisce l'autorizzazione senza token e con `tokenDelivered: true`, così l'archivio di idempotenza non contiene mai una credenziale. Se il token è perso, revocate l'autorizzazione e createne una nuova. Il campo `notice` lo dice nella risposta.

**I ruoli delle autorità restano nella dashboard.** `market_surveillance`, `notified_body`, `commission` e `customs`, e il livello `authority` sul ruolo `other`, rispondono `400 role_dashboard_only`. Il registro degli accessi annota quale chiave API o app ha creato l'autorizzazione.

**Chi può chiamarlo.** Una chiave API solo se il suo titolare ha attivato «May manage access grants» per quella chiave nella pagina Developer (disattivato per impostazione predefinita; altrimenti `403 access_grants_not_enabled`). Un token OAuth richiede lo scope `access_grants:write` e un utente admin o owner. Richiede un account a pagamento. Conta come una scrittura v1.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Authorization` | header | string | yes | `Bearer <token>` — una chiave API `tp_` (Developer → API Keys; più semplice, per server-to-server) oppure un access token OAuth 2.0 (Developer → OAuth Apps; per app autorizzate dall'utente, scoped e revocabili). La pagina Authentication contiene il flusso OAuth completo e l'elenco degli scopes. |
| `Idempotency-Key` | header | string | no | UUID v4. |
| `role` | body | string | yes | Il ruolo del destinatario: `repairer`, `remanufacturer`, `repurposer`, `recycler`, `waste_treatment`, `training_centre`, `purchaser`, `purchaser_agent`, `elv_treatment`, `weee_treatment` oppure `other`. I quattro ruoli delle autorità sono rifiutati. |
| `label` | body | string (1-120 chars) | yes | Per chi è l'autorizzazione, come desiderate vederla. |
| `scope` | body | object | no | `{ "kind": "company" }`, `{ "kind": "products", "ids": \[...\] }` oppure `{ "kind": "passports", "ids": \[...\] }` (fino a 500 id, tutti nella vostra azienda). Un'autorizzazione da acquirente deve elencare passaporti. |
| `purpose` | body | string (max 500 chars) | no | Perché il destinatario ottiene l'accesso. |
| `evidence` | body | object | no | `{ type, reference, note? }`, dove `type` è `register_entry`, `invoice`, `authority_letter`, `contract` oppure `other`. Registrata, non verificata. |
| `expiresInDays` | body | integer \| null (1-1825) | no | Giorni alla scadenza. Omettere per il valore predefinito del ruolo (12 mesi; nessuno per un acquirente, la cui autorizzazione termina al cambio di proprietà). `null` = nessuna scadenza. |

## 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 — Creata (token mostrato una volta)

```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 — Ripetizione idempotente (senza 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 — Ruolo di autorità

```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 — Interruttore spento

```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

- [Elencare le autorizzazioni di accesso](https://www.tracepass.eu/it/docs/list-access-grants.md)
- [Revocare un'autorizzazione di accesso](https://www.tracepass.eu/it/docs/revoke-access-grant.md)
