# Upsert a conversation

Operation ID: `patient.commsUpsertConversation`

Create or update a CareConnect conversation, keyed by client-supplied `id`. Idempotent. Requires a Bearer JWT (any authenticated pool type).

## Public method

`upsertConversation`

Signature: `patient.upsertConversation(request)`

Return type: `Promise<ConversationRecord>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`POST /communications/conversations`

## Path parameters

None.

## Query parameters

None.

## Body parameters

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

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

## Request example

```json
{
  "createdAt": "2026-08-10T23:37:16.021510Z",
  "groupId": "sdk-group-20260811-013559",
  "id": "sdk-conversation-20260811-013559",
  "kind": "group",
  "lastMessagePreview": "Your care plan is ready for review.",
  "participantIds": [
    "sdk-contact-20260811-013559"
  ],
  "title": "SDK Patient Test",
  "unreadCount": 0,
  "updatedAt": "2026-08-10T23:37:16.021516Z"
}
```

## Success responses

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

## Success response examples

### 201

```json
{
  "createdAt": "2026-08-10T23:37:16.021510Z",
  "groupId": "sdk-group-20260811-013559",
  "id": "sdk-conversation-20260811-013559",
  "kind": "group",
  "lastMessagePreview": "Your care plan is ready for review.",
  "participantIds": [
    "sdk-contact-20260811-013559"
  ],
  "title": "SDK Patient Test",
  "unreadCount": 0,
  "updatedAt": "2026-08-10T23:37:16.021516Z"
}
```

## 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": [
        "kind"
      ],
      "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 { UpsertConversationRequest } from "@healthcloudai/hc-sdk";
```

```ts
const request = {
  "createdAt": "2026-08-10T23:37:16.021510Z",
  "groupId": "sdk-group-20260811-013559",
  "id": "sdk-conversation-20260811-013559",
  "kind": "group",
  "lastMessagePreview": "Your care plan is ready for review.",
  "participantIds": [
    "sdk-contact-20260811-013559"
  ],
  "title": "SDK Patient Test",
  "unreadCount": 0,
  "updatedAt": "2026-08-10T23:37:16.021516Z"
};

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

## cURL

```bash
curl -X POST \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{"createdAt":"2026-08-10T23:37:16.021510Z","groupId":"sdk-group-20260811-013559","id":"sdk-conversation-20260811-013559","kind":"group","lastMessagePreview":"Your care plan is ready for review.","participantIds":["sdk-contact-20260811-013559"],"title":"SDK Patient Test","unreadCount":0,"updatedAt":"2026-08-10T23:37:16.021516Z"}' \
  'https://dev-api-patient.health.cloud/communications/conversations'
```

## 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.
