# Change public resource token

Canonical page: https://docs.ovok.com/api/public-resource-access/change-public-resource-token

`PATCH /public/{resourceType}/{id}`

Gives a resource a new public token, so it can be read with `GET /public/{token}`. If the resource already has a token, the old one is replaced and stops working.

**Auth:** bearer token of a project admin.

## Behaviour

- The resource must be in the caller's project or one of its sub-projects. A resource of any other project, the parent project included, answers `403` and is left unchanged; an unknown id answers `404`.
- The token is written to the resource's `meta.extension` with the URL `https://api.ovok.com/fhir/StructureDefinition/public-resource-token`. Other extensions are kept.
- The response is `{ token, resource }`: the new token and the updated resource.

## Example

```bash
curl -X PATCH 'https://api.sandbox.ovok.com/public/DocumentReference/87ea5dfc-8b8e-384d-8489-79496e706390' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjcyNjg4MDAsImV4cCI6MTc2NzI3MjQwMH0.Ql3B_ztDvctlyZ2z0vp4sl3ExXRQGkzmxdmTAqxNzZk'
```

```json
{
  "token": "...",
  "resource": {
    "resourceType": "DocumentReference",
    "id": "87ea5dfc-8b8e-384d-8489-79496e706390",
    "meta": {
      "extension": [
        { "url": "https://api.ovok.com/fhir/StructureDefinition/public-resource-token", "valueString": "..." }
      ]
    },
    ...
  }
}
```
