# Update phone number

Operation ID: `patient.updatePhone`

Update the authenticated patient's phone number in FHIR and Cognito, then send an SMS OTP to the new number. Follow up with `patient.verifySms` to confirm it. Requires a patient Bearer JWT; the patient is always resolved from the token, never from client input.

## Public method

`updatePhone`

Signature: `patient.updatePhone(request)`

Return type: `Promise<PhoneUpdateResponse>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`POST /patients/phone`

## Path parameters

None.

## Query parameters

None.

## Body parameters

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

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

## Request example

```json
{
  "phone": "+12025550123"
}
```

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `200` | [`patient.UpdatePhoneResponse`](../models/patient.UpdatePhoneResponse.md) | application/json | Phone updated and SMS OTP dispatched |

## Success response examples

### 200

```json
{
  "sms_otp_sent": true
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `400` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | Bad request — phone is missing, malformed, or not a dialable number |
| `401` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | Authorization required — missing, invalid, expired, or non-patient Bearer JWT |
| `404` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | The authenticated patient has no FHIR Patient record |
| `502` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | The SMS provider could not be reached or rejected our credentials. The phone number itself was accepted; this is a server-side fault, so the request may be retried unchanged. |

## Error examples

### 400 — Not E.164 format

```json
{
  "error": "phone: 'abc-def-ghij' is not a valid phone number. Expected E.164 format (e.g. +12065551234)"
}
```

### 400 — phone is required

```json
{
  "error": "phone is required"
}
```

### 400 — The number is well-formed but the SMS provider will not deliver to it (e.g. a landline, or an unsubscribed recipient)

```json
{
  "error": "Twilio error 21614: 'To' number is not a valid mobile number"
}
```

### 400 — Correct length and E.164, but not a dialable US/Canada number

```json
{
  "error": "phone: '+11234123412' is not a dialable US/Canada number — the area code and exchange code must each start with 2-9 and must not be a service code like 411 (e.g. +12065551234)"
}
```

### 401 — Missing or invalid access token

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

### 404 — Patient not found

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

### 502 — Our SMS provider credentials are invalid or expired

```json
{
  "error": "Twilio error 20003: Authentication Error - invalid username"
}
```

### 502 — The SMS provider returned a server error

```json
{
  "error": "Twilio error: Internal Server Error"
}
```

## NodeJS / TypeScript implementation

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

```ts
const request = {
  "phone": "+12025550123"
};

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

## cURL

```bash
curl -X POST \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{"phone":"+12025550123"}' \
  'https://dev-api-patient.health.cloud/patients/phone'
```

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