# Create a PatientConnection

`POST /v1/patients/:patient_id/connections`

Connects the Patient to an existing Organization, such as a GP practice. If the Patient is already connected, Carebit returns that PatientConnection and grants this Organization access. This endpoint does not create Organizations. Search with `GET /v1/organizations` first.

**Required API scopes:** `patient_connections.create`

## Parameters

- `patient_id` (path, `string`) (required)
- `Idempotency-Key` (header, `string`) (required) - Client-generated idempotency key. Required for every POST/PATCH write. Replay of the same key with the same body returns the stored response with an `Idempotency-Replayed: true` header. Same key + different body returns `422 idempotency_key_reused`. A duplicate that arrives while the first request is still in flight returns `409 idempotency_conflict` with `Retry-After: 1`.

## Request body (`application/json`)

- `object`
  - `clinician_id` (`string | null`) - format: `uuid`; The Clinician at the target Organization. The Clinician must already belong to that Organization. Pass `null` on update to remove the Clinician.
  - `gp_status` (`string | null`) - enum: `none_or_omitted`, `has_gp`, `no_gp_required`, `null`; Whether this Organization has recorded a GP for the Patient.
  - `is_active` (`boolean`) - Whether the PatientConnection is active. Defaults to `true` on create.
  - `organization_id` (`string`) - format: `uuid`; The existing Organization to connect the Patient to. Required on create. This endpoint does not create Organizations.
  - `payor_id` (`string`) - format: `uuid`; The Patient's Payor this Organization should use as the default billing party. The Payor must belong to the Patient.

### Example

```json
{
  "organization_id": "00000000-0000-4000-8000-000000000018"
}
```

## Response `200`

The Patient was already connected to the Organization. Carebit returned the existing PatientConnection.

- `object`
  - `clinician_id` (`string | null`) - format: `uuid`; The Clinician associated with this registration, when one is assigned.
  - `created_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.
  - `gp_status` (`string | null`) - enum: `none_or_omitted`, `has_gp`, `no_gp_required`, `null`; Whether this Organization has recorded a GP for the Patient. `has_gp` means a GP PatientConnection is expected. `no_gp_required` means the Patient does not need a GP. `none_or_omitted` means no GP has been recorded.
  - `id` (`string`) - format: `uuid`; The resource's unique identifier, formatted as an RFC 4122 version 4 UUID.
  - `is_active` (`boolean`) - Whether the Patient registration is active.
  - `links` (`object`) - URLs to related resources.
    - `patient` (`string`) - format: `uri`; The full URL of a related resource.
    - `payor` (`string | null`) - format: `uri`; The full URL of a related resource.
  - `object` (`any`) - Discriminator value emitted at `object`.
  - `organization` (`object`)
    - `address_line_1` (`string | null`) - The primary address line of the organization.
    - `address_line_2` (`string | null`) - The secondary address line of the organization.
    - `city` (`string | null`) - The city in the organization's postal address.
    - `country_code` (`string | null`) - The ISO 3166-1 alpha-2 country code for the postal address, such as `GB` for the United Kingdom.
    - `county` (`string | null`) - The county or region in the organization's postal address.
    - `created_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.
    - `currency` (`string | null`) - The ISO 4217 currency code used by the organization. Must be one of `chf`, `eur`, `gbp`, or `usd`. Null when this Organization is returned from `GET /v1/organizations` or nested on a PatientConnection.
    - `email` (`string | null`) - format: `email`; The contact email address of the organization. Null when this Organization is returned from `GET /v1/organizations` or nested on a PatientConnection.
    - `formatted_address` (`string | null`) - The single-line address of the organization, formatted for display.
    - `id` (`string`) - format: `uuid`; The resource's unique identifier, formatted as an RFC 4122 version 4 UUID.
    - `name` (`string`) - The display name of the organization, for example `Acme Healthcare`.
    - `object` (`any`) - Discriminator value emitted at `object`.
    - `organization_type` (`string | null`) - enum: `consultant`, `gp_practice`, `hospital`, `laboratory`, `legal`, `other`, `pharmacy`, `private_practice`, `null`; The kind of organization. Use `gp_practice` when attaching a GP.
    - `phone` (`string | null`) - The formatted contact phone number of the organization. Null when this Organization is returned from `GET /v1/organizations` or nested on a PatientConnection.
    - `postcode` (`string | null`) - The postal code in the organization's postal address.
    - `subdomain` (`string | null`) - The URL-safe subdomain that identifies the organization. Null when this Organization is returned from `GET /v1/organizations` or nested on a PatientConnection.
    - `time_zone` (`string | null`) - The IANA time zone used to interpret scheduling dates and display appointment times. Always `Europe/London` when present. Null when this Organization is returned from `GET /v1/organizations` or nested on a PatientConnection.
    - `updated_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.
  - `organization_id` (`string`) - format: `uuid`; The Organization with which the Patient was registered.
  - `patient` (`object`)
    - `address_line_1` (`string | null`) - The primary address line of the Patient.
    - `address_line_2` (`string | null`) - The secondary address line of the Patient.
    - `city` (`string | null`) - The city in the Patient's postal address.
    - `country_code` (`string | null`) - The ISO 3166-1 alpha-2 country code for the postal address, such as `GB` for the United Kingdom.
    - `county` (`string | null`) - The county or region in the Patient's postal address.
    - `created_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.
    - `creation_source` (`string | null`) - How the Patient was created. `api` means the record was created through the Developer Platform. Read-only.
    - `date_of_birth` (`string | null`) - format: `date`; The date of birth of the patient, in ISO 8601 format (YYYY-MM-DD).
    - `display_name` (`string | null`) - The formatted display name of the patient, including their title when recorded.
    - `email` (`string | null`) - format: `email`; The email address of the patient, when recorded.
    - `first_name` (`string | null`) - The first name of the patient.
    - `id` (`string`) - format: `uuid`; The resource's unique identifier, formatted as an RFC 4122 version 4 UUID.
    - `is_opted_out_of_sms` (`boolean`) - Whether the Patient has opted out of SMS messages.
    - `last_name` (`string | null`) - The last name of the patient.
    - `mobile` (`string | null`) - The national mobile number without its country calling code.
    - `mobile_country_dial_code` (`string | null`) - The ISO 3166-1 alpha-2 country code used to derive the mobile calling code.
    - `nhs_number` (`string | null`) - The 10-digit NHS number of the patient, without formatting.
    - `object` (`any`) - Discriminator value emitted at `object`.
    - `phone` (`string | null`) - The national phone number without its country calling code.
    - `phone_country_dial_code` (`string | null`) - The ISO 3166-1 alpha-2 country code used to derive the phone calling code.
    - `phone_number` (`string | null`) - The Patient's preferred contact number, formatted for display and compatible with E.164.
    - `postcode` (`string | null`) - The postal code of the Patient.
    - `sex` (`string | null`) - enum: `female`, `male`, `other`, `null`; The Patient's recorded sex.
    - `title` (`string | null`) - The personal title of the patient, when recorded.
    - `updated_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.
  - `payor_id` (`string | null`) - format: `uuid`; The Payor this Organization uses as the default billing party for the Patient.
  - `updated_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.

### Example

```json
{
  "id": "fcdd446b-eef0-4bf2-83d1-35764265817d",
  "object": "patient_connection",
  "clinician_id": "2b3c4d5e-6f70-489a-9bcd-ef0123456789",
  "created_at": "2026-01-01T09:00:00Z",
  "gp_status": "none_or_omitted",
  "is_active": true,
  "links": {
    "patient": "https://api.carebit.co/v1/patients/1a2b3c4d-5e6f-4789-8abc-def012345678",
    "payor": "https://api.carebit.co/v1/payors/708192a3-b4c5-4def-8012-3456789abcde"
  },
  "organization": {
    "id": "8192a3b4-c5d6-4ef0-9123-456789abcdef",
    "object": "organization",
    "address_line_1": "10 Harley Street",
    "address_line_2": "Marylebone",
    "city": "London",
    "country_code": "GB",
    "county": "Greater London",
    "created_at": "2026-01-01T09:00:00Z",
    "currency": "GBP",
    "email": "alex.morgan@example.com",
    "formatted_address": "10 Harley Street, Marylebone, London, W1G 9PF",
    "name": "Harley Street Clinic",
    "organization_type": "consultant",
    "phone": "2071234567",
    "postcode": "W1G 9PF",
    "subdomain": "harley-street-clinic",
    "time_zone": "Example time zone",
    "updated_at": "2026-01-01T09:00:00Z"
  },
  "organization_id": "8192a3b4-c5d6-4ef0-9123-456789abcdef",
  "patient": {
    "id": "1a2b3c4d-5e6f-4789-8abc-def012345678",
    "object": "patient",
    "address_line_1": "10 Harley Street",
    "address_line_2": "Marylebone",
    "city": "London",
    "country_code": "GB",
    "county": "Greater London",
    "created_at": "2026-01-01T09:00:00Z",
    "creation_source": "api",
    "date_of_birth": "1990-01-01",
    "display_name": "Dr Alex Morgan",
    "email": "alex.morgan@example.com",
    "first_name": "Alex",
    "is_opted_out_of_sms": false,
    "last_name": "Morgan",
    "mobile": "7700900123",
    "mobile_country_dial_code": "GB",
    "nhs_number": "485 777 3456",
    "phone": "2071234567",
    "phone_country_dial_code": "GB",
    "phone_number": "+44 7700 900123",
    "postcode": "W1G 9PF",
    "sex": "female",
    "title": "Dr",
    "updated_at": "2026-01-01T09:00:00Z"
  },
  "payor_id": "708192a3-b4c5-4def-8012-3456789abcde",
  "updated_at": "2026-01-01T09:00:00Z"
}
```

## Response `201`

PatientConnection created.

- `object`
  - `clinician_id` (`string | null`) - format: `uuid`; The Clinician associated with this registration, when one is assigned.
  - `created_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.
  - `gp_status` (`string | null`) - enum: `none_or_omitted`, `has_gp`, `no_gp_required`, `null`; Whether this Organization has recorded a GP for the Patient. `has_gp` means a GP PatientConnection is expected. `no_gp_required` means the Patient does not need a GP. `none_or_omitted` means no GP has been recorded.
  - `id` (`string`) - format: `uuid`; The resource's unique identifier, formatted as an RFC 4122 version 4 UUID.
  - `is_active` (`boolean`) - Whether the Patient registration is active.
  - `links` (`object`) - URLs to related resources.
    - `patient` (`string`) - format: `uri`; The full URL of a related resource.
    - `payor` (`string | null`) - format: `uri`; The full URL of a related resource.
  - `object` (`any`) - Discriminator value emitted at `object`.
  - `organization` (`object`)
    - `address_line_1` (`string | null`) - The primary address line of the organization.
    - `address_line_2` (`string | null`) - The secondary address line of the organization.
    - `city` (`string | null`) - The city in the organization's postal address.
    - `country_code` (`string | null`) - The ISO 3166-1 alpha-2 country code for the postal address, such as `GB` for the United Kingdom.
    - `county` (`string | null`) - The county or region in the organization's postal address.
    - `created_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.
    - `currency` (`string | null`) - The ISO 4217 currency code used by the organization. Must be one of `chf`, `eur`, `gbp`, or `usd`. Null when this Organization is returned from `GET /v1/organizations` or nested on a PatientConnection.
    - `email` (`string | null`) - format: `email`; The contact email address of the organization. Null when this Organization is returned from `GET /v1/organizations` or nested on a PatientConnection.
    - `formatted_address` (`string | null`) - The single-line address of the organization, formatted for display.
    - `id` (`string`) - format: `uuid`; The resource's unique identifier, formatted as an RFC 4122 version 4 UUID.
    - `name` (`string`) - The display name of the organization, for example `Acme Healthcare`.
    - `object` (`any`) - Discriminator value emitted at `object`.
    - `organization_type` (`string | null`) - enum: `consultant`, `gp_practice`, `hospital`, `laboratory`, `legal`, `other`, `pharmacy`, `private_practice`, `null`; The kind of organization. Use `gp_practice` when attaching a GP.
    - `phone` (`string | null`) - The formatted contact phone number of the organization. Null when this Organization is returned from `GET /v1/organizations` or nested on a PatientConnection.
    - `postcode` (`string | null`) - The postal code in the organization's postal address.
    - `subdomain` (`string | null`) - The URL-safe subdomain that identifies the organization. Null when this Organization is returned from `GET /v1/organizations` or nested on a PatientConnection.
    - `time_zone` (`string | null`) - The IANA time zone used to interpret scheduling dates and display appointment times. Always `Europe/London` when present. Null when this Organization is returned from `GET /v1/organizations` or nested on a PatientConnection.
    - `updated_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.
  - `organization_id` (`string`) - format: `uuid`; The Organization with which the Patient was registered.
  - `patient` (`object`)
    - `address_line_1` (`string | null`) - The primary address line of the Patient.
    - `address_line_2` (`string | null`) - The secondary address line of the Patient.
    - `city` (`string | null`) - The city in the Patient's postal address.
    - `country_code` (`string | null`) - The ISO 3166-1 alpha-2 country code for the postal address, such as `GB` for the United Kingdom.
    - `county` (`string | null`) - The county or region in the Patient's postal address.
    - `created_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.
    - `creation_source` (`string | null`) - How the Patient was created. `api` means the record was created through the Developer Platform. Read-only.
    - `date_of_birth` (`string | null`) - format: `date`; The date of birth of the patient, in ISO 8601 format (YYYY-MM-DD).
    - `display_name` (`string | null`) - The formatted display name of the patient, including their title when recorded.
    - `email` (`string | null`) - format: `email`; The email address of the patient, when recorded.
    - `first_name` (`string | null`) - The first name of the patient.
    - `id` (`string`) - format: `uuid`; The resource's unique identifier, formatted as an RFC 4122 version 4 UUID.
    - `is_opted_out_of_sms` (`boolean`) - Whether the Patient has opted out of SMS messages.
    - `last_name` (`string | null`) - The last name of the patient.
    - `mobile` (`string | null`) - The national mobile number without its country calling code.
    - `mobile_country_dial_code` (`string | null`) - The ISO 3166-1 alpha-2 country code used to derive the mobile calling code.
    - `nhs_number` (`string | null`) - The 10-digit NHS number of the patient, without formatting.
    - `object` (`any`) - Discriminator value emitted at `object`.
    - `phone` (`string | null`) - The national phone number without its country calling code.
    - `phone_country_dial_code` (`string | null`) - The ISO 3166-1 alpha-2 country code used to derive the phone calling code.
    - `phone_number` (`string | null`) - The Patient's preferred contact number, formatted for display and compatible with E.164.
    - `postcode` (`string | null`) - The postal code of the Patient.
    - `sex` (`string | null`) - enum: `female`, `male`, `other`, `null`; The Patient's recorded sex.
    - `title` (`string | null`) - The personal title of the patient, when recorded.
    - `updated_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.
  - `payor_id` (`string | null`) - format: `uuid`; The Payor this Organization uses as the default billing party for the Patient.
  - `updated_at` (`string`) - format: `date-time`; An ISO 8601 timestamp in UTC, with a `Z` suffix. For example, `2026-07-01T09:00:00Z`.

### Example

```json
{
  "id": "fcdd446b-eef0-4bf2-83d1-35764265817d",
  "object": "patient_connection",
  "clinician_id": "2b3c4d5e-6f70-489a-9bcd-ef0123456789",
  "created_at": "2026-01-01T09:00:00Z",
  "gp_status": "none_or_omitted",
  "is_active": true,
  "links": {
    "patient": "https://api.carebit.co/v1/patients/1a2b3c4d-5e6f-4789-8abc-def012345678",
    "payor": "https://api.carebit.co/v1/payors/708192a3-b4c5-4def-8012-3456789abcde"
  },
  "organization": {
    "id": "8192a3b4-c5d6-4ef0-9123-456789abcdef",
    "object": "organization",
    "address_line_1": "10 Harley Street",
    "address_line_2": "Marylebone",
    "city": "London",
    "country_code": "GB",
    "county": "Greater London",
    "created_at": "2026-01-01T09:00:00Z",
    "currency": "GBP",
    "email": "alex.morgan@example.com",
    "formatted_address": "10 Harley Street, Marylebone, London, W1G 9PF",
    "name": "Harley Street Clinic",
    "organization_type": "consultant",
    "phone": "2071234567",
    "postcode": "W1G 9PF",
    "subdomain": "harley-street-clinic",
    "time_zone": "Example time zone",
    "updated_at": "2026-01-01T09:00:00Z"
  },
  "organization_id": "8192a3b4-c5d6-4ef0-9123-456789abcdef",
  "patient": {
    "id": "1a2b3c4d-5e6f-4789-8abc-def012345678",
    "object": "patient",
    "address_line_1": "10 Harley Street",
    "address_line_2": "Marylebone",
    "city": "London",
    "country_code": "GB",
    "county": "Greater London",
    "created_at": "2026-01-01T09:00:00Z",
    "creation_source": "api",
    "date_of_birth": "1990-01-01",
    "display_name": "Dr Alex Morgan",
    "email": "alex.morgan@example.com",
    "first_name": "Alex",
    "is_opted_out_of_sms": false,
    "last_name": "Morgan",
    "mobile": "7700900123",
    "mobile_country_dial_code": "GB",
    "nhs_number": "485 777 3456",
    "phone": "2071234567",
    "phone_country_dial_code": "GB",
    "phone_number": "+44 7700 900123",
    "postcode": "W1G 9PF",
    "sex": "female",
    "title": "Dr",
    "updated_at": "2026-01-01T09:00:00Z"
  },
  "payor_id": "708192a3-b4c5-4def-8012-3456789abcde",
  "updated_at": "2026-01-01T09:00:00Z"
}
```

## Response `400`

The `Idempotency-Key` header is missing (`idempotency_key_required`) or exceeds 255 characters (`idempotency_key_too_long`).

- `object`
  - `error` (`object`) - The structured details that describe why the request failed.
    - `code` (`string`) - The machine-readable error code.
    - `errors` (`array | null`) - Additional errors from a failed validation.
      - `items` (`object`)
        - `code` (`string`) - The machine-readable code for this validation error.
        - `message` (`string`) - A message that explains this validation error.
        - `param` (`string | null`) - The name of the parameter that caused this validation error, when known.
    - `message` (`string`) - A message that explains the error and how to resolve it.
    - `param` (`string | null`) - The name of the parameter that caused the error, when known.
    - `type` (`string`) - enum: `authentication_error`, `permission_error`, `invalid_request_error`, `rate_limit_error`, `api_error`; The high-level category of the error.

### Example

```json
{
  "error": {
    "code": "resource_missing",
    "errors": [
      {
        "code": "resource_missing",
        "message": "The requested resource was not found.",
        "param": "patient_id"
      }
    ],
    "message": "The requested resource was not found.",
    "param": "patient_id",
    "type": "authentication_error"
  }
}
```

## Response `401`

The access token is missing, invalid, expired, or revoked.

- `object`
  - `error` (`object`) - The structured details that describe why the request failed.
    - `code` (`string`) - The machine-readable error code.
    - `errors` (`array | null`) - Additional errors from a failed validation.
      - `items` (`object`)
        - `code` (`string`) - The machine-readable code for this validation error.
        - `message` (`string`) - A message that explains this validation error.
        - `param` (`string | null`) - The name of the parameter that caused this validation error, when known.
    - `message` (`string`) - A message that explains the error and how to resolve it.
    - `param` (`string | null`) - The name of the parameter that caused the error, when known.
    - `type` (`string`) - enum: `authentication_error`, `permission_error`, `invalid_request_error`, `rate_limit_error`, `api_error`; The high-level category of the error.

### Example

```json
{
  "error": {
    "code": "resource_missing",
    "errors": [
      {
        "code": "resource_missing",
        "message": "The requested resource was not found.",
        "param": "patient_id"
      }
    ],
    "message": "The requested resource was not found.",
    "param": "patient_id",
    "type": "authentication_error"
  }
}
```

## Response `403`

The access token lacks the required scope, or the project is disabled.

- `object`
  - `error` (`object`) - The structured details that describe why the request failed.
    - `code` (`string`) - The machine-readable error code.
    - `errors` (`array | null`) - Additional errors from a failed validation.
      - `items` (`object`)
        - `code` (`string`) - The machine-readable code for this validation error.
        - `message` (`string`) - A message that explains this validation error.
        - `param` (`string | null`) - The name of the parameter that caused this validation error, when known.
    - `message` (`string`) - A message that explains the error and how to resolve it.
    - `param` (`string | null`) - The name of the parameter that caused the error, when known.
    - `type` (`string`) - enum: `authentication_error`, `permission_error`, `invalid_request_error`, `rate_limit_error`, `api_error`; The high-level category of the error.

### Example

```json
{
  "error": {
    "code": "resource_missing",
    "errors": [
      {
        "code": "resource_missing",
        "message": "The requested resource was not found.",
        "param": "patient_id"
      }
    ],
    "message": "The requested resource was not found.",
    "param": "patient_id",
    "type": "authentication_error"
  }
}
```

## Response `404`

The Patient, Organization, Clinician, or Payor was not found.

- `object`
  - `error` (`object`) - The structured details that describe why the request failed.
    - `code` (`string`) - The machine-readable error code.
    - `errors` (`array | null`) - Additional errors from a failed validation.
      - `items` (`object`)
        - `code` (`string`) - The machine-readable code for this validation error.
        - `message` (`string`) - A message that explains this validation error.
        - `param` (`string | null`) - The name of the parameter that caused this validation error, when known.
    - `message` (`string`) - A message that explains the error and how to resolve it.
    - `param` (`string | null`) - The name of the parameter that caused the error, when known.
    - `type` (`string`) - enum: `authentication_error`, `permission_error`, `invalid_request_error`, `rate_limit_error`, `api_error`; The high-level category of the error.

### Example

```json
{
  "error": {
    "code": "resource_missing",
    "errors": [
      {
        "code": "resource_missing",
        "message": "The requested resource was not found.",
        "param": "patient_id"
      }
    ],
    "message": "The requested resource was not found.",
    "param": "patient_id",
    "type": "authentication_error"
  }
}
```

## Response `409`

A concurrent request holds the idempotency lease (`idempotency_conflict`). Retry after the delay indicated by `Retry-After`.

- `object`
  - `error` (`object`) - The structured details that describe why the request failed.
    - `code` (`string`) - The machine-readable error code.
    - `errors` (`array | null`) - Additional errors from a failed validation.
      - `items` (`object`)
        - `code` (`string`) - The machine-readable code for this validation error.
        - `message` (`string`) - A message that explains this validation error.
        - `param` (`string | null`) - The name of the parameter that caused this validation error, when known.
    - `message` (`string`) - A message that explains the error and how to resolve it.
    - `param` (`string | null`) - The name of the parameter that caused the error, when known.
    - `type` (`string`) - enum: `authentication_error`, `permission_error`, `invalid_request_error`, `rate_limit_error`, `api_error`; The high-level category of the error.

### Example

```json
{
  "error": {
    "code": "resource_missing",
    "errors": [
      {
        "code": "resource_missing",
        "message": "The requested resource was not found.",
        "param": "patient_id"
      }
    ],
    "message": "The requested resource was not found.",
    "param": "patient_id",
    "type": "authentication_error"
  }
}
```

## Response `422`

The `Idempotency-Key` was previously used with a different request body (`idempotency_key_reused`), or the request body failed validation.

- `object`
  - `error` (`object`) - The structured details that describe why the request failed.
    - `code` (`string`) - The machine-readable error code.
    - `errors` (`array | null`) - Additional errors from a failed validation.
      - `items` (`object`)
        - `code` (`string`) - The machine-readable code for this validation error.
        - `message` (`string`) - A message that explains this validation error.
        - `param` (`string | null`) - The name of the parameter that caused this validation error, when known.
    - `message` (`string`) - A message that explains the error and how to resolve it.
    - `param` (`string | null`) - The name of the parameter that caused the error, when known.
    - `type` (`string`) - enum: `authentication_error`, `permission_error`, `invalid_request_error`, `rate_limit_error`, `api_error`; The high-level category of the error.

### Example

```json
{
  "error": {
    "code": "resource_missing",
    "errors": [
      {
        "code": "resource_missing",
        "message": "The requested resource was not found.",
        "param": "patient_id"
      }
    ],
    "message": "The requested resource was not found.",
    "param": "patient_id",
    "type": "authentication_error"
  }
}
```

## Response `429`

Too many requests. Retry after the delay indicated by `Retry-After`.

- `object`
  - `error` (`object`) - The structured details that describe why the request failed.
    - `code` (`string`) - The machine-readable error code.
    - `errors` (`array | null`) - Additional errors from a failed validation.
      - `items` (`object`)
        - `code` (`string`) - The machine-readable code for this validation error.
        - `message` (`string`) - A message that explains this validation error.
        - `param` (`string | null`) - The name of the parameter that caused this validation error, when known.
    - `message` (`string`) - A message that explains the error and how to resolve it.
    - `param` (`string | null`) - The name of the parameter that caused the error, when known.
    - `type` (`string`) - enum: `authentication_error`, `permission_error`, `invalid_request_error`, `rate_limit_error`, `api_error`; The high-level category of the error.

### Example

```json
{
  "error": {
    "code": "resource_missing",
    "errors": [
      {
        "code": "resource_missing",
        "message": "The requested resource was not found.",
        "param": "patient_id"
      }
    ],
    "message": "The requested resource was not found.",
    "param": "patient_id",
    "type": "authentication_error"
  }
}
```

## Code samples

```bash
curl -X POST "https://api.carebit.co/v1/patients/8f14e45f-ea7d-4b6f-9c2a-1d3e5f7a9b0c/connections" \
  -H "Authorization: Bearer $CAREBIT_ACCESS_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "organization_id": "00000000-0000-4000-8000-000000000018"
}'
```

```javascript
const response = await fetch("https://api.carebit.co/v1/patients/8f14e45f-ea7d-4b6f-9c2a-1d3e5f7a9b0c/connections", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.CAREBIT_ACCESS_TOKEN}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
  "organization_id": "00000000-0000-4000-8000-000000000018"
}),
});

if (!response.ok) {
  throw new Error(`Carebit API error: ${response.status}`);
}

const data = await response.json();
```

```python
import os
import requests
import uuid

response = requests.post(
    "https://api.carebit.co/v1/patients/8f14e45f-ea7d-4b6f-9c2a-1d3e5f7a9b0c/connections",
    headers={
        "Authorization": f"Bearer {os.environ['CAREBIT_ACCESS_TOKEN']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "organization_id": "00000000-0000-4000-8000-000000000018"
    }
)
response.raise_for_status()
data = response.json()
```

```ruby
require "httparty"
require "json"
require "securerandom"

response = HTTParty.post(
  "https://api.carebit.co/v1/patients/8f14e45f-ea7d-4b6f-9c2a-1d3e5f7a9b0c/connections",
  headers: {
    "Authorization" => "Bearer #{ENV.fetch("CAREBIT_ACCESS_TOKEN")}",
    "Idempotency-Key" => SecureRandom.uuid,
    "Content-Type" => "application/json"
  },
  body: {
    "organization_id" => "00000000-0000-4000-8000-000000000018"
  }.to_json
)
raise "Carebit API error: #{response.code}" unless response.success?
data = response.parsed_response
```

```php
<?php

$client = new GuzzleHttp\Client();

$response = $client->post("https://api.carebit.co/v1/patients/8f14e45f-ea7d-4b6f-9c2a-1d3e5f7a9b0c/connections", [
    "headers" => [
      "Authorization" => "Bearer " . getenv("CAREBIT_ACCESS_TOKEN"),
      "Idempotency-Key" => bin2hex(random_bytes(16)),
    ],
    "json" => [
      "organization_id" => "00000000-0000-4000-8000-000000000018"
    ]
]);
$data = json_decode((string) $response->getBody(), true, flags: JSON_THROW_ON_ERROR);
```
