# Cancel an appointment

Operation ID: `appointments.cancel`

Cancel the identified appointment. On a FHIR-only tenant this releases the appointment's associated slots. On a vendor-integrated tenant (Athena, OpenLoop, SteadyMD) the booking exists only in the vendor, so the cancellation is executed there — and fails there — with no FHIR fallback. Pass the `appointment_id` returned by booking or patient appointment listing (the vendor appointment id on vendor-integrated tenants). The optional `reason` body field is forwarded to the vendor where its API accepts one (e.g. Athena's cancel reason).

## Public method

`cancel`

Signature: `appointments.cancel(appointmentId)`

Return type: `Promise<Appointment>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`POST /appointments/{appointment_id}/cancel`

## Path parameters

| Name | Type | Required | Format | Allowed values | Default | Nullable | Description |
|---|---|---:|---|---|---|---:|---|
| `appointment_id` | `string` | Yes |  |  |  | No |  |

## Query parameters

None.

## Body parameters

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

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

## Request example

```json
{
  "reason": "Patient no longer needs the visit"
}
```

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `200` | [`Appointment`](../models/Appointment.md) | application/json | Appointment cancelled successfully |

## Success response examples

### 200

```json
{
  "appointment_id": "string",
  "athena_appointment_id": "string",
  "created_at": "string",
  "end": "string",
  "openloop_appointment_id": "string",
  "patient_id": "string",
  "provider_id": "string",
  "slot_id": "string",
  "slot_ids": [
    "string"
  ],
  "specialty_code": "string",
  "start": "string",
  "status": "scheduled",
  "steadymd_consult_guid": "string",
  "telehealth_link": "string",
  "updated_at": "string"
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `401` | [`appointments.ErrorResponse`](../models/appointments.ErrorResponse.md) | application/json | Authorization required — missing or invalid Bearer JWT |
| `404` | [`appointments.ErrorResponse`](../models/appointments.ErrorResponse.md) | application/json | The appointment was not found — in FHIR, or in the vendor, or it has no linked HealthCloud patient |
| `409` | [`appointments.ErrorResponse`](../models/appointments.ErrorResponse.md) | application/json | Vendor-integrated tenant: the vendor rejected the cancellation as a business rule |
| `500` | [`appointments.ErrorResponse`](../models/appointments.ErrorResponse.md) | application/json | Internal server error |
| `502` | [`appointments.ErrorResponse`](../models/appointments.ErrorResponse.md) | application/json | Vendor-integrated tenant: the vendor failed or did not confirm the cancellation |

## Error examples

### 401 — Missing or invalid access token

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

### 404 — FHIR Appointment resource does not exist

```json
{
  "error": "Not Found"
}
```

### 404 — Vendor-integrated tenant: the vendor reports no such appointment

```json
{
  "error": "Appointment not found in Athena: HTTP 404"
}
```

### 404 — Vendor-integrated tenant: the vendor appointment has no linked HealthCloud patient

```json
{
  "error": "Appointment not found"
}
```

### 409 — The vendor refused to cancel (e.g. already cancelled, or past its cancellation window)

```json
{
  "error": "Appointment cannot be changed in Athena: appointment is already cancelled"
}
```

### 500 — Unexpected service failure (sanitized example)

```json
{
  "error": "Internal server error"
}
```

### 502 — Vendor answered 200 but did not confirm the cancellation

```json
{
  "error": "Athena did not confirm appointment 123 as cancelled"
}
```

## NodeJS / TypeScript implementation

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

```ts
const appointmentId = "<APPOINTMENT_ID>";

const result = await appointments.cancel(appointmentId);
```

## cURL

```bash
curl -X POST \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{"reason":"Patient no longer needs the visit"}' \
  'https://dev-api-appointments.health.cloud/appointments/%3CAPPOINTMENT_ID%3E/cancel'
```

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