# End a share

Canonical page: https://docs.ovok.com/api/patient-sharing/end-a-share

`DELETE /v1/patient-sharing/shares/{consentId}`

Ends a share, cancels a pending invite, or declines a practitioner's invite. A related person (a carer) leaves a share they received. Access stops at once.

**Auth:** bearer token of a Patient or a RelatedPerson.
**Scope:** the caller's project (from the token).

## Behaviour

- Who may call it, by `consentId`:
  - a patient-to-patient share: the sharer or the recipient;
  - a pending patient-to-patient invite: the sharer (this cancels it);
  - a share of the caller's record with a practitioner, or a practitioner's pending invite to the caller: the patient.
  - a share of the caller's codes with a related person, or its pending invite: the patient;
  - a share a patient gave the caller as their related person: the related person (see below).
- A practitioner gets 403.
- Every grant bound to the Consent is removed from the members who hold it, and the Consent is set to `inactive`, in one atomic write. The holders' cached sessions are refreshed.
- Calling it again on an ended share only sweeps any grants left behind, so retrying is safe.
- If the records keep changing during the write, it retries up to three times, then answers 409. Retry the call.
- Returns `204 No Content`.

## A related person leaving a share

- The Consent is set to `inactive`, as when the patient ends it, and its grant leaves the caller's own membership, in one atomic write. The caller's cached sessions are refreshed.
- The membership keeps its base policy. One that had lost it gets it back, so it never reads as full project access.
- `404` when the share is not one the caller received, for example another carer's or a patient-to-patient share. It never says whose it is.
- `409` when the share already ended, or a record changed during the write. Read the list again and retry.

## Example

```bash
curl -X DELETE 'https://api.sandbox.ovok.com/v1/patient-sharing/shares/c3499c27-2973-0a7f-807e-fb8676a92dcb' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjcyNjg4MDAsImV4cCI6MTc2NzI3MjQwMH0.Ql3B_ztDvctlyZ2z0vp4sl3ExXRQGkzmxdmTAqxNzZk'
```
