# Upsert an invite

Operation ID: `patient.commsUpsertInvite`

Create or update a CareConnect invite, keyed by client-supplied `id`. Idempotent. No real SMS/email is sent in dev deployments. Requires a Bearer JWT (any authenticated pool type).

## Public method

`upsertInvite`

Signature: `patient.upsertInvite(request)`

Return type: `Promise<InviteRecord>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`POST /communications/invites`

## Path parameters

None.

## Query parameters

None.

## Body parameters

| Name | Type | Required | Format | Allowed values | Default | Nullable | Description |
|---|---|---:|---|---|---|---:|---|
| `body` | [`UpsertInviteRequest`](../models/UpsertInviteRequest.md) | Yes |  |  |  | No |  |

Request model: [`UpsertInviteRequest`](../models/UpsertInviteRequest.md)

## Request example

```json
{
  "channel": "email",
  "createdAt": "2026-08-10T23:37:17Z",
  "destination": "test.user@example.com",
  "id": "invite-example-001",
  "name": "Test User",
  "role": "patient",
  "status": "sent"
}
```

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `201` | [`InviteRecord`](../models/InviteRecord.md) | application/json | Invite upserted |

## Success response examples

### 201

```json
{
  "channel": "email",
  "createdAt": "2026-08-10T23:37:17Z",
  "destination": "test.user@example.com",
  "id": "invite-example-001",
  "inviteCode": "INVITE-EXAMPLE-001",
  "name": "Test User",
  "role": "patient",
  "status": "sent"
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `400` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | The request body failed schema validation |
| `401` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | Authorization required — missing or invalid Bearer JWT |
| `403` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | The caller's token carries no tenant context |

## Error examples

### 400 — The request body failed validation

```json
{
  "details": [
    {
      "loc": [
        "destination"
      ],
      "msg": "Field required",
      "type": "missing"
    }
  ],
  "error": "Invalid request body"
}
```

### 401 — Missing or invalid access token

```json
{
  "error": "Authorization required"
}
```

### 403 — Tenant context unavailable

```json
{
  "error": "Tenant context unavailable"
}
```

## NodeJS / TypeScript implementation

```ts
import { HCSDK } from "@healthcloudai/hc-sdk";
import type { UpsertInviteRequest } from "@healthcloudai/hc-sdk";
```

```ts
const request = {
  "channel": "email",
  "createdAt": "2026-08-10T23:37:17Z",
  "destination": "test.user@example.com",
  "id": "invite-example-001",
  "name": "Test User",
  "role": "patient",
  "status": "sent"
};

const result = await patient.upsertInvite(request);
```

## cURL

```bash
curl -X POST \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{"channel":"email","createdAt":"2026-08-10T23:37:17Z","destination":"test.user@example.com","id":"invite-example-001","name":"Test User","role":"patient","status":"sent"}' \
  'https://dev-api-patient.health.cloud/communications/invites'
```

## Notes

None.

## Prepared Test Console scenario

No canonical scenario is currently associated.

## Real response

No approved real integration response is currently published. Unapproved candidates are never rendered as examples.
