# ovok.sharing

Canonical page: https://docs.ovok.com/web-sdk/core/namespaces/sharing

`ovok.sharing` lets a patient share chosen observation codes with another person, and see or revoke those shares. Patient apps call it for the signed-in patient. A project admin turns sharing on in the sharing settings.

## Invite someone [#invite-someone]

The patient creates an invite for a set of observation codes and passes the `inviteId` and `code` to the recipient.

```ts
const invite = await ovok.sharing.invites.create({
  codes: ['8867-4'],
  endsAt: null,
});

console.log(invite.inviteId, invite.code, invite.expiresAt);
```

- `endsAt` is an ISO 8601 end time, or `null` for no end.
- The invite expires at `expiresAt`.

## Redeem an invite [#redeem-an-invite]

The recipient redeems it while signed in.

```ts
const share = await ovok.sharing.invites.redeem({ inviteId, code });
```

- It resolves to the created share.
- To accept a record-share invite with the active profile, `ovok.invites.accept` picks the right route for you.

## List and revoke shares [#list-and-revoke-shares]

```ts
const { outgoing, incoming, practitioners, relatedPersons, received } = await ovok.sharing.shares.list();

await ovok.sharing.shares.revoke(consentId);
```

- Groups the server does not send yet come back as empty arrays.
- `revoke` takes the id of the share's consent.

## Change sharing settings [#change-sharing-settings]

```ts
const settings = await ovok.sharing.settings.retrieve();

await ovok.sharing.settings.update({ enabled: true, practitionerSharingEnabled: true });
```

- `update` replaces the settings. `practitionerSharingEnabled: null` leaves that flag unchanged.

## Reference [#reference]

- [sharing API reference](/web-sdk/core/reference/core/sharing): every method and type.
- [invites guide](/web-sdk/core/namespaces/invites)
- [Errors and retries](/web-sdk/core/errors-and-retries)
