# Convenience method: find the first available slot on a given day and book it

Operation ID: `connectors.healthieFindAndBookFirstAvailableSlot`

Convenience method: find the first available slot on a given day and book it. When auth_context is None but user_id is set, books via createAppointment with enforce_availability=False; otherwise uses completeCheckout. Returns the booked appointment or None. enforce_availability is deliberately sent as False (not omitted): with True, Healthie's own slot-collision check times out server-side (QUERY_TIMEOUT/REQUEST_TIMEOUT, ~30s) whenever the assigned provider isn't the API key's own identity — confirmed live, reproducibly, for any real active provider. Per Luka, this is a known Healthie-side edge case with org-level slots, to be fixed on their end separately; False is the accepted interim booking path. Since dropping enforce_availability removes Healthie's own collision check, candidate slots are verified against a real appointments() lookup (not availableSlotsForRange — confirmed live to not reflect existing bookings), fetched once per attempt via _fetch_provider_appointments and reused for every candidate's overlap check; slots that already conflict are skipped in favor of the next one. Fetching per-candidate instead of once was tried first and reverted — confirmed live 2026-09-02 it made booking fragile for a provider with a large real appointment history.

## Public method

`findAndBookFirstAvailableSlot`

Signature: `connectors.healthie.createClient(config).findAndBookFirstAvailableSlot(body)`

Return type: `Promise<HealthieAppointmentResponse>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`POST /connectors/healthie/find-and-book-first-available-slot`

## Path parameters

None.

## Query parameters

None.

## Body parameters

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

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

## Request example

```json
{
  "api_url": "https://example.com/resource",
  "appt_type_id": "12345",
  "contact_type": "example-contact-type",
  "date": "example-date",
  "mode": "sandbox",
  "open_loop_url": "https://example.com/resource",
  "provider_id": "12345",
  "secret_key": "example-api-key",
  "shard_id": "12345",
  "timezone": "example-timezone"
}
```

## Success responses

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

## Success response examples

### 200

```json
{
  "appointment_type_id": "12345",
  "attendees": [],
  "contact_type": "example-contact-type",
  "current_position_in_recurring_series": "example-current-position-in-recurring-series",
  "date": "example-date",
  "end": "example-end",
  "id": "12345",
  "length": "example-length",
  "location": "example-location",
  "notes": "example-notes",
  "pm_status": "example-pm-status",
  "recurring_appointment_id": "12345",
  "start": "example-start",
  "status": "example-status",
  "zoom_join_url": "https://example.com/resource",
  "zoom_meeting_id": "12345"
}
```

## 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 { HealthieFindAndBookFirstAvailableSlotRequest } from "@healthcloudai/hc-sdk";
```

```ts
const body = {
  "api_url": "https://example.com/resource",
  "appt_type_id": "12345",
  "contact_type": "example-contact-type",
  "date": "example-date",
  "mode": "sandbox",
  "open_loop_url": "https://example.com/resource",
  "provider_id": "12345",
  "secret_key": "example-api-key",
  "shard_id": "12345",
  "timezone": "example-timezone"
};

const result = await connectors.healthie.createClient(config).findAndBookFirstAvailableSlot(body);
```

## cURL

```bash
curl -X POST \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{"api_url":"https://example.com/resource","appt_type_id":"12345","contact_type":"example-contact-type","date":"example-date","mode":"sandbox","open_loop_url":"https://example.com/resource","provider_id":"12345","secret_key":"example-api-key","shard_id":"12345","timezone":"example-timezone"}' \
  'https://dev-api-connectors.health.cloud/connectors/healthie/find-and-book-first-available-slot'
```

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