> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usecobalt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch Availability

> Performs a live fetch of provider availability by combining a real-time EMR appointment fetch with availability calculation.

<Note>
  This is an async operation that fetches up-to-date appointment data directly from the EMR and computes availability in one pass. If freshness is not critical, use `GET /availability` instead, which returns availability against cached appointment data.
</Note>

## Request Constraints

* `provider_ids`: required array of EMR provider IDs. Must contain between 1 and 10 entries.
* A single provider may span up to a 5-day window.
* Two or more providers must share a single date (`start_date` must equal `end_date`).

All availability-calculation parameters (`calculation_method`, `daily_appointment_limit`, `daily_limit_type`, `provider_type`, `fallback_to_default_hours`, `max_slot_duration`, `facility_scoped_scheduling`, `location_ids`) are optional and follow the same defaults and validation rules as `GET /availability`.

### Example Request (1 provider, 5 days)

```json theme={null}
{
    "start_date": "2026-07-01",
    "end_date": "2026-07-05",
    "provider_ids": ["prov_789"],
    "calculation_method": "gaps"
}
```

### Example Request (multiple providers, single day)

```json theme={null}
{
    "start_date": "2026-07-01",
    "end_date": "2026-07-01",
    "provider_ids": ["prov_789", "prov_790", "prov_791"]
}
```

## Webhook Notification

When the fetch completes, we send an `availability.live_fetch_completed` event to your registered webhook endpoint with the computed slots inline. The slots themselves are not persisted, but as a side effect the underlying appointments returned by the EMR are written to our appointments cache — a follow-up `GET /availability` reflects the live state.

```json theme={null}
{
    "id": "evt_1J9X2q2eZvKYlo2Cmnopqr",
    "access_token_reference_id": "user_1J9X2q2eZvKYlo2Cstuv",
    "job_id": "job_1J9X2q2eZvKYlo2Cmnopqr",
    "timestamp": "2026-07-01T11:00:00Z",
    "type": "availability.live_fetch_completed",
    "action": "sync",
    "data": {
        "success": true,
        "provider_ids": ["prov_789"],
        "start_date": "2026-07-01",
        "end_date": "2026-07-05",
        "slot_count": 24,
        "slots": [
            {
                "day_of_week": 3,
                "date": "2026-07-01",
                "duration_string": "30 minutes",
                "range_start": "2026-07-01T09:00:00-07:00",
                "range_end": "2026-07-01T09:30:00-07:00",
                "provider_id": "prov_789",
                "facility_id": "loc_1",
                "facility_name": "Main Office"
            }
        ]
    }
}
```

Each slot always includes `day_of_week` (1-7, ISO weekday), `date` (YYYY-MM-DD), `duration_string`, `range_start`, `range_end`, and `provider_id`. `facility_id` and `facility_name` are present when the source EHR scopes the shift to a specific location. `visit_type`, `available_appointments`, and `max_visits` appear when `calculation_method` is `slots` or `equal_slots`.


## OpenAPI

````yaml POST /availability/fetch
openapi: 3.0.0
info:
  title: Cobalt API
  version: 1.0.1
  description: API for interacting with Cobalt's EHR integration services
servers:
  - url: https://api.usecobalt.com/v1
security:
  - ClientCredentials: []
    ClientSecret: []
    AccessToken: []
paths:
  /availability/fetch:
    post:
      summary: Fetch Availability
      description: >-
        Performs a live fetch of provider availability by combining a real-time
        EMR appointment fetch with the same availability calculation used by
        `GET /availability`. Asynchronous: returns 202 immediately and delivers
        the computed slots via webhook. As a side effect, the underlying
        appointments are written to your appointments cache, so a follow-up `GET
        /appointments` reflects the live state. eClinicalWorks only.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - start_date
                - end_date
                - provider_ids
              properties:
                start_date:
                  type: string
                  format: date
                  description: >-
                    Start date for the availability window in ISO 8601 format
                    (YYYY-MM-DD).
                end_date:
                  type: string
                  format: date
                  description: >-
                    End date for the availability window in ISO 8601 format
                    (YYYY-MM-DD). When 1 provider is supplied, `end_date` may be
                    up to 5 days after `start_date`. When 2-10 providers are
                    supplied, `end_date` must equal `start_date`.
                provider_ids:
                  type: array
                  items:
                    type: string
                  minItems: 1
                  maxItems: 10
                  description: EMR provider IDs to compute availability for (1-10).
                calculation_method:
                  type: string
                  enum:
                    - gaps
                    - slots
                    - equal_slots
                  default: gaps
                  description: >-
                    Availability calculation strategy. Same semantics as `GET
                    /availability`.
                daily_appointment_limit:
                  type: integer
                  minimum: 1
                  description: >-
                    Same semantics as `GET /availability`. Requires
                    `daily_limit_type`.
                daily_limit_type:
                  type: string
                  description: >-
                    Same semantics as `GET /availability`. Requires
                    `daily_appointment_limit`.
                provider_type:
                  type: string
                  enum:
                    - primary
                    - secondary
                fallback_to_default_hours:
                  type: boolean
                  description: Same semantics as `GET /availability`.
                max_slot_duration:
                  type: integer
                  minimum: 5
                  maximum: 60
                  multipleOf: 5
                  description: Same semantics as `GET /availability`.
                facility_scoped_scheduling:
                  type: boolean
                  description: Same semantics as `GET /availability`.
                location_ids:
                  type: array
                  items:
                    type: string
                  description: EHR location IDs to filter slots by `facility_id`.
      responses:
        '202':
          description: Request accepted for processing. Results are delivered via webhook.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  job_id:
                    type: string
        '400':
          description: Bad request (validation failure or unsupported EMR).
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
components:
  securitySchemes:
    ClientCredentials:
      type: apiKey
      in: header
      name: client_id
    ClientSecret:
      type: apiKey
      in: header
      name: client_secret
    AccessToken:
      type: apiKey
      in: header
      name: access_token

````