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

# Book an appointment

> Books an appointment. Send **exactly one** of:

- `slot_token` from a slot search, together with `patient_id` — books directly.
- `reservation_id` from a hold — confirms it. The patient, provider, and window come from the hold, so `patient_id` is not needed and is ignored.

Scheduling selects the provider; the 201 response carries the assigned `provider_id`. The appointment is returned bare, not wrapped in a `data` envelope.

A 409 means the window was claimed between your search and this call — search again and offer the patient a fresh slot. `notes` is plain text only; angle brackets are rejected.



## OpenAPI

````yaml /openapi.json post /appointments
openapi: 3.1.0
info:
  title: OpenLoop API
  version: 0.1.0
  description: >-
    Unified reference for the OpenLoop Patient (clinical) and Payments & Revenue
    APIs.
servers:
  - url: https://api.openloophealth.com/v0.1
    description: Production partner edge
  - url: https://api-staging.openloophealth.com/v0.1
    description: Staging partner edge (sandbox credentials)
security: []
paths:
  /appointments:
    post:
      tags:
        - Scheduling
      summary: Book an appointment
      description: >-
        Books an appointment. Send **exactly one** of:


        - `slot_token` from a slot search, together with `patient_id` — books
        directly.

        - `reservation_id` from a hold — confirms it. The patient, provider, and
        window come from the hold, so `patient_id` is not needed and is ignored.


        Scheduling selects the provider; the 201 response carries the assigned
        `provider_id`. The appointment is returned bare, not wrapped in a `data`
        envelope.


        A 409 means the window was claimed between your search and this call —
        search again and offer the patient a fresh slot. `notes` is plain text
        only; angle brackets are rejected.
      parameters:
        - name: Idempotency-Key
          in: header
          required: true
          schema:
            type: string
            minLength: 1
            maxLength: 255
          description: >-
            Required. A UUID your client generates, one per attempt. The first
            request under a key is processed and its response stored for 24
            hours; a later request under the same key returns that stored
            response with `x-idempotency-replayed: true` instead of writing
            again, so a retry after a timeout cannot double-book. Failures are
            stored too — use a new key whenever you change the request or search
            for a new slot. Omitting the header is a 400
            (`missing-idempotency-key`). A key is global to your integration,
            not scoped to an endpoint or an appointment, so mint a fresh UUID
            per action rather than deriving one from the resource — a key
            already spent on a booking will replay that booking if you send it
            on a later cancel or complete.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                slot_token:
                  type: string
                  minLength: 1
                  maxLength: 8192
                  description: >-
                    A `slot_token` from a slot search. Mutually exclusive with
                    `reservation_id`.
                reservation_id:
                  type: string
                  format: uuid
                  description: >-
                    A `reservation_id` from a hold. Mutually exclusive with
                    `slot_token`.
                patient_id:
                  type: string
                  format: uuid
                  description: >-
                    The patient, as returned by `POST /patients`. Required only
                    when the `slot_token` names no patient — that is, when the
                    slot search did not send `patient_id`. Otherwise optional: a
                    matching value is accepted, and a different one is a 400
                    (`slot_token.patient_mismatch`). Omit on the
                    `reservation_id` path.
                notes:
                  type: string
                  maxLength: 2000
                  description: >-
                    Pre-visit notes for the appointment, up to 2000 characters.
                    Plain text only: a value containing `<` or `>` is rejected
                    with a 400 (`appointment.notes-invalid-html`).
      responses:
        '201':
          description: The booked appointment, including the assigned provider.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SchedulingAppointment'
        '400':
          description: >-
            Request validation failed: malformed body, both or neither of
            `slot_token`/`reservation_id`, an expired token, HTML in `notes`, or
            a missing `Idempotency-Key` (`missing-idempotency-key`). Also
            `patient_id` missing for a token that names no patient, or differing
            from the token's patient (`slot_token.patient_mismatch`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/SchedulingProblem'
        '401':
          description: Missing or invalid bearer token.
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/SchedulingProblem'
        '403':
          description: >-
            Authorization denied — your credentials do not carry the capability
            this endpoint requires, or the token's organization claim is not one
            you may act for.
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/SchedulingProblem'
        '404':
          description: >-
            The slot token references an appointment-type variant that no longer
            exists.
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/SchedulingProblem'
        '409':
          description: >-
            The slot is no longer available — another booking holds the window.
            Search again.
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/SchedulingProblem'
        '422':
          description: '`slot_token.tampered` — the token failed integrity verification.'
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/SchedulingProblem'
        '500':
          description: >-
            A transient persistence error aborted the write; the request may be
            retried.
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/SchedulingProblem'
      security:
        - serviceToken: []
        - userToken: []
components:
  schemas:
    SchedulingAppointment:
      type: object
      description: >-
        A booked appointment. Returned bare (not wrapped in a `data` envelope)
        by the single-appointment endpoints. Carries no `organization_id` — your
        org comes from the access token.
      properties:
        id:
          type: string
          format: uuid
        provider_id:
          type: string
          format: uuid
          description: The provider scheduling assigned at book time.
        patient_id:
          type: string
          format: uuid
        start:
          type: string
          format: date-time
        end:
          type: string
          format: date-time
        status:
          type: string
          enum:
            - open
            - closed
          description: >-
            Lifecycle state. `closed` is terminal; read `outcome` for how it
            closed.
        outcome:
          type: string
          enum:
            - completed
            - no_show
            - cancelled
            - unresolved
          description: Present once the appointment closes.
        state:
          type: string
          minLength: 2
          maxLength: 2
          description: Two-letter US state the visit was licensed against.
        closed_at:
          type: string
          format: date-time
          description: >-
            When the appointment closed, however it closed — completed, no-show
            or cancelled. Present once `status` is `closed`.
        cancelled_at:
          type: string
          format: date-time
        cancel_reason:
          type: string
        notes:
          type: string
          description: Pre-visit notes, when the booking set them.
        external_refs:
          type: array
          description: Identifiers this appointment carries in downstream systems.
          items:
            type: object
            properties:
              system:
                type: string
              id:
                type: string
            required:
              - system
              - id
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      required:
        - id
        - provider_id
        - patient_id
        - start
        - end
        - status
        - created_at
        - updated_at
    SchedulingProblem:
      type: object
      description: >-
        RFC 7807 problem detail. Scheduling endpoints return errors as
        `application/problem+json`, not the platform `{ error, request_id }`
        envelope. `code` is the stable machine-readable identifier — branch on
        it, not on `detail`.
      properties:
        type:
          type: string
          description: Problem type URI. `about:blank` for the codes below.
        title:
          type: string
          description: Short human-readable summary, e.g. `Bad Request`.
        status:
          type: integer
          description: The HTTP status code, repeated in the body.
        detail:
          type: string
          description: Human-readable explanation of this occurrence.
        instance:
          type: string
        code:
          type: string
          description: >-
            Stable error identifier, e.g. `slot_search.window_too_large`,
            `appointment_list.offset_required`, `slot_token.tampered`.
          examples:
            - slot_search.window_too_large
        errors:
          type: array
          description: >-
            Field-level validation failures, when the error is a body/query
            validation failure.
          items:
            type: object
            properties:
              field:
                type: string
              message:
                type: string
              code:
                type: string
            required:
              - field
              - message
              - code
      required:
        - type
        - title
        - status
        - code
  securitySchemes:
    serviceToken:
      type: oauth2
      description: >-
        Service (M2M) access token issued by POST /auth/token using the
        client_credentials grant. Required scopes, where known, are listed on
        each operation below.
      flows:
        clientCredentials:
          tokenUrl: https://api.openloophealth.com/v0.1/auth/token
          scopes: {}
    userToken:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        User access token issued by POST /auth/token via the verification-code
        grant (after Verify a one-time code) or the refresh_token grant.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.