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

# Create a contact

> **Permission:** `crm.contacts:write` Create a CRM contact. Never starts outreach. Mirrors db/actions/crm.ts createCrmContact's own validation, defaults, and default-pipeline/stage resolution. is_email_domain_blocked is checked server-side on any email. Both crm_contacts outreach triggers (an Agent Studio automation, a marketing-journey enrollment) are suppressed unconditionally for this write.



## OpenAPI

````yaml /openapi/ehr-api.v1.yaml post /v1/clinics/{clinic_id}/crm/contacts
openapi: 3.1.0
info:
  title: ClinikEHR API
  version: 1.0.0
  description: >-
    Server-to-server REST API for a clinic's own data, reached with a key the
    clinic (or a developer workspace) creates in the developer portal.


    Authenticate every request with `Authorization: Bearer <key>`. Test keys
    reach only your workspace's own synthetic sandbox; live keys reach the
    clinic that created them. Lists wrap their rows as `{ data, has_more,
    next_cursor }`; single resources are returned directly. Errors are
    `application/problem+json` (RFC 9457) with a stable `code`.


    Write requests accept an `Idempotency-Key` header so a retry never repeats a
    change. See the guides for authentication, permissions, pagination, rate
    limits and retries.
servers:
  - url: https://api.clinikehr.com
security:
  - ApiKey: []
paths:
  /v1/clinics/{clinic_id}/crm/contacts:
    post:
      tags:
        - CRM
      summary: Create a contact
      description: >-
        **Permission:** `crm.contacts:write` Create a CRM contact. Never starts
        outreach. Mirrors db/actions/crm.ts createCrmContact's own validation,
        defaults, and default-pipeline/stage resolution. is_email_domain_blocked
        is checked server-side on any email. Both crm_contacts outreach triggers
        (an Agent Studio automation, a marketing-journey enrollment) are
        suppressed unconditionally for this write.
      operationId: createCrmContact
      parameters:
        - $ref: '#/components/parameters/IdempotencyKeyRequired'
        - name: clinic_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CrmContactCreateRequest'
      responses:
        '200':
          description: OK.
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    $ref: '#/components/schemas/CrmContact'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '409':
          $ref: '#/components/responses/Conflict'
        '429':
          $ref: '#/components/responses/TooManyRequests'
      security:
        - ApiKey: []
components:
  parameters:
    IdempotencyKeyRequired:
      name: Idempotency-Key
      in: header
      required: true
      description: >-
        A unique value you choose for this request, such as a UUID. Sending the
        same key again returns the first answer instead of doing the work twice,
        so a timed-out request is safe to retry. Reusing a key for a different
        request is refused with `409 idempotency_key_conflict`, and retrying
        while the first request is still running with `409
        idempotency_key_reused`. See Retries and idempotency.
      schema:
        type: string
        minLength: 1
  schemas:
    CrmContactCreateRequest:
      type: object
      additionalProperties: false
      properties:
        owner_staff_id:
          type:
            - string
            - 'null'
          format: uuid
        record_type:
          type: string
          enum:
            - lead
            - prospect
            - waitlist
            - referral
            - contact
        first_name:
          type:
            - string
            - 'null'
        last_name:
          type:
            - string
            - 'null'
        email:
          type:
            - string
            - 'null'
        phone:
          type:
            - string
            - 'null'
        company:
          type:
            - string
            - 'null'
        lifecycle_stage:
          type: string
          enum:
            - lead
            - inquiry
            - prospect
            - waitlist
            - customer
            - lost
        pipeline_id:
          type:
            - string
            - 'null'
          format: uuid
        stage_id:
          type:
            - string
            - 'null'
          format: uuid
        source:
          type: string
        referral_source_id:
          type:
            - string
            - 'null'
          format: uuid
        interest:
          type:
            - string
            - 'null'
        desired_service_id:
          type:
            - string
            - 'null'
          format: uuid
        desired_provider_id:
          type:
            - string
            - 'null'
          format: uuid
        estimated_value_cents:
          type:
            - integer
            - 'null'
        priority:
          type: string
          enum:
            - low
            - normal
            - high
        marketing_opt_in:
          type: boolean
        sms_opt_in:
          type: boolean
        tags:
          type: array
          items:
            type: string
        custom_fields:
          type: object
    CrmContact:
      type: object
      description: >-
        Withheld, by NAME: clinic_id (implicit in the path), unsubscribe_token,
        migrated_from_patient_id, custom_color, created_by, confirmed_opt_in_at,
        marketing_authorization_id.
      required:
        - id
      properties:
        id:
          type: string
          format: uuid
        owner_staff_id:
          type:
            - string
            - 'null'
          format: uuid
        record_type:
          type:
            - string
            - 'null'
          enum:
            - lead
            - prospect
            - waitlist
            - referral
            - contact
            - null
        first_name:
          type:
            - string
            - 'null'
        last_name:
          type:
            - string
            - 'null'
        email:
          type:
            - string
            - 'null'
        phone:
          type:
            - string
            - 'null'
        company:
          type:
            - string
            - 'null'
        lifecycle_stage:
          type:
            - string
            - 'null'
          enum:
            - lead
            - inquiry
            - prospect
            - waitlist
            - customer
            - lost
            - null
        pipeline_id:
          type:
            - string
            - 'null'
          format: uuid
        stage_id:
          type:
            - string
            - 'null'
          format: uuid
        status:
          type:
            - string
            - 'null'
        source:
          type:
            - string
            - 'null'
        referral_source_id:
          type:
            - string
            - 'null'
          format: uuid
        referred_by_contact_id:
          type:
            - string
            - 'null'
          format: uuid
        interest:
          type:
            - string
            - 'null'
        desired_service_id:
          type:
            - string
            - 'null'
          format: uuid
        desired_provider_id:
          type:
            - string
            - 'null'
          format: uuid
        estimated_value_cents:
          type:
            - integer
            - 'null'
        currency:
          type:
            - string
            - 'null'
        priority:
          type:
            - string
            - 'null'
          enum:
            - low
            - normal
            - high
            - null
        score:
          type:
            - integer
            - 'null'
        marketing_opt_in:
          type:
            - boolean
            - 'null'
        sms_opt_in:
          type:
            - boolean
            - 'null'
        consent_at:
          type:
            - string
            - 'null'
          format: date-time
        consent_source:
          type:
            - string
            - 'null'
        do_not_contact:
          type:
            - boolean
            - 'null'
        unsubscribed_at:
          type:
            - string
            - 'null'
          format: date-time
        tags:
          type: array
          items:
            type: string
        custom_fields:
          type: object
        converted_patient_id:
          type:
            - string
            - 'null'
          format: uuid
        converted_at:
          type:
            - string
            - 'null'
          format: date-time
        lost_reason:
          type:
            - string
            - 'null'
        last_activity_at:
          type:
            - string
            - 'null'
          format: date-time
        next_task_at:
          type:
            - string
            - 'null'
          format: date-time
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
    Problem:
      type: object
      description: RFC 9457 application/problem+json.
      required:
        - type
        - title
        - status
        - code
        - request_id
      properties:
        type:
          type: string
          format: uri
        title:
          type: string
        status:
          type: integer
        detail:
          type: string
        code:
          type: string
        request_id:
          type: string
        errors:
          type: array
          items:
            type: object
            required:
              - pointer
              - message
            properties:
              pointer:
                type: string
              message:
                type: string
  responses:
    BadRequest:
      description: >-
        The request failed validation (unknown query parameter, limit out of
        range, malformed body).
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
    Unauthorized:
      description: >-
        Missing, malformed, unknown, revoked or expired key, or the wrong
        secret.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
    Forbidden:
      description: >-
        The key or connection lacks the required scope, the plan does not
        include this resource, the request came from an address this key's IP
        allow-list does not permit, a TEST-environment workspace key asked for a
        clinic_id other than its own workspace's sandbox (`sandbox_only`), or a
        LIVE workspace key asked for a real clinic while its workspace's
        verification has lapsed (`not_verified`) — the response never names
        which addresses ARE allowed, nor which clinic actually is the sandbox.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
    Conflict:
      description: >-
        The request is well-formed but conflicts with the CURRENT STATE of the
        record — a double-booked slot (`slot_taken`), a clinician's calendar
        blocked at that time (`out_of_office`), nobody eligible free
        (`no_provider_available`), an item that still has stock
        (`item_has_stock`), a ledger movement that cannot be covered
        (`insufficient_stock`, `expired_stock_not_transferable`), a note already
        signed or clinician-touched (`note_not_editable`), an Idempotency-Key
        already used for a different request or still in flight
        (`idempotency_key_conflict`, `idempotency_key_reused`), or an
        external-stock batch rejected as structurally invalid or a suspicious
        shrink versus the clinic's last accepted batch (`batch_rejected`), or an
        outside record that conflicts with what was already submitted or
        decided: the same `client_reference` sent again with different content
        (`client_reference_conflict`), or a submission a clinician has already
        decided (`submission_not_pending`), or an insurance write that conflicts
        with the clinic's setup or the coverage's state: the patient already has
        a coverage for that payer (`coverage_exists`, the existing coverage's id
        is in `detail` when the caller can see that patient), a payer the clinic
        has not enabled in Settings → Insurance (`payer_not_enabled`), or
        `coverage_active: true` sent through the API
        (`activation_requires_staff` — only clinic staff activate a coverage),
        or a change to an outside care provider the clinic added rather than an
        app (`care_provider_clinic_managed` — only the clinic can change or
        remove it).
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
    TooManyRequests:
      description: Rate limited. See the Retry-After header.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
  securitySchemes:
    ApiKey:
      type: http
      scheme: bearer
      bearerFormat: ehr_live_<keyId>_<secret> or ehr_test_<keyId>_<secret>

````

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