# Exchange code (Apple)

Operation ID: `connectors.appleAuthExchangeCode`

Exchange code via Apple. Returns an AppleTokenResponse record.

## Public method

`exchangeCode`

Signature: `connectors.appleAuth.createClient(config).exchangeCode(body)`

Return type: `Promise<AppleAuthExchangeCodeResult>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`POST /connectors/apple-auth/exchange-code`

## Path parameters

None.

## Query parameters

None.

## Body parameters

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

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

## Request example

```json
{
  "authorization_code": "example-api-key",
  "client_id": "12345",
  "key_id": "12345",
  "mode": "sandbox",
  "private_key": "example-api-key",
  "redirect_uri": "example-redirect-uri",
  "team_id": "12345"
}
```

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `200` | [`AppleAuthExchangeCodeResponse`](../models/AppleAuthExchangeCodeResponse.md) | application/json | Successful response |

## Success response examples

### 200

```json
{
  "access_token": "example-access-token",
  "expires_in": 1,
  "id_token": "example-id-token",
  "refresh_token": "example-refresh-token",
  "token_type": "example-token-type"
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `400` | [`StandardErrorResponse`](../models/StandardErrorResponse.md) | application/json | Connector validation rejected the payload, or a required field was missing or of the wrong type. |
| `401` | [`StandardErrorResponse`](../models/StandardErrorResponse.md) | application/json | The HealthCloud bearer token is missing or invalid, or the vendor rejected the supplied connector credentials. |
| `500` | [`StandardErrorResponse`](../models/StandardErrorResponse.md) | application/json | The connector failed unexpectedly. |
| `502` | [`StandardErrorResponse`](../models/StandardErrorResponse.md) | application/json | The vendor returned an application or transport-level failure. |
| `504` | [`StandardErrorResponse`](../models/StandardErrorResponse.md) | application/json | The vendor did not respond within the connector timeout. |

## Error examples

### 400 — Invalid request

```json
{
  "error": "Invalid request"
}
```

### 401 — Authorization required

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

### 500 — Internal error

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

### 502 — Upstream vendor error

```json
{
  "error": "Upstream vendor error"
}
```

### 504 — Upstream timeout

```json
{
  "error": "Upstream timeout"
}
```

## NodeJS / TypeScript implementation

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

```ts
const body = {
  "authorization_code": "example-api-key",
  "client_id": "12345",
  "key_id": "12345",
  "mode": "sandbox",
  "private_key": "example-api-key",
  "redirect_uri": "example-redirect-uri",
  "team_id": "12345"
};

const result = await connectors.appleAuth.createClient(config).exchangeCode(body);
```

## cURL

```bash
curl -X POST \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{"authorization_code":"example-api-key","client_id":"12345","key_id":"12345","mode":"sandbox","private_key":"example-api-key","redirect_uri":"example-redirect-uri","team_id":"12345"}' \
  'https://dev-api-connectors.health.cloud/connectors/apple-auth/exchange-code'
```

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