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

# CRM

> Push leads and bookings into the Flabs CRM from your own funnels.

The CRM API has four endpoints. Use them in this order:

```mermaid theme={null}
flowchart TB
    A[POST /client/auth/token]
    B[GET /client/labs<br/>pick a branchID]
    C[GET /client/crm/tests<br/>?branchID=...]
    D[GET /client/crm/packages<br/>?branchID=...]
    E[POST /client/crm/lead/create]
    F{phase}
    G[Telecaller picks it up<br/>and converts it into a booking]
    H[Booking is scheduled<br/>and shows up in the phlebo app]

    A --> B
    B --> C
    B --> D
    C --> E
    D --> E
    E --> F
    F -->|lead| G
    F -->|booking| H
```

## Integration modes

Your account runs in one of two modes. Most accounts use **catch-all** — this page covers it. If your business routes work per referring corporate, doctor, or hospital, use **party-scoped**.

<CardGroup cols={2}>
  <Card title="Catch-all (default)" icon="globe">
    No party needed. Tests/packages return standard branch pricing, and one webhook receives every event for the lab. **This page.**
  </Card>

  <Card title="Party-scoped (B2B)" icon="building-user" href="/crm/party-scoped">
    For a doctor's CRM, a hospital portal, a wellness app, or a corporate health dashboard. Every lead, booking, and price is tied to a corporate / doctor / hospital, and each gets its own webhook. Enabled by Flabs — contact support.
  </Card>
</CardGroup>

## Endpoints

<CardGroup cols={2}>
  <Card title="List Branches" icon="building" href="/crm/endpoint/list_branches">
    Fetch the branches under your account.
  </Card>

  <Card title="List Tests" icon="vial" href="/crm/endpoint/list_tests">
    Fetch every test offered by a branch.
  </Card>

  <Card title="List Packages" icon="boxes-stacked" href="/crm/endpoint/list_packages">
    Fetch every package offered by a branch.
  </Card>

  <Card title="Create Lead or Booking" icon="user-plus" href="/crm/endpoint/create_lead">
    Create a CRM entry. Phase decides whether it's a lead or a booking.
  </Card>
</CardGroup>

## Lead vs Booking

|                         | Lead (default) | Booking                                                                  |
| ----------------------- | -------------- | ------------------------------------------------------------------------ |
| `phase`                 | `"lead"`       | `"booking"`                                                              |
| Auto-assign             | ✅ telecaller   | ❌                                                                        |
| Notification            | `NEW_LEAD`     | `BOOKING_CONFIRMED`                                                      |
| Required booking fields | –              | `bookingType`, `scheduledAt`                                             |
| Defaults set by server  | –              | `bookingStatus: Scheduled`, `paymentStatus: Pending`, `convertedAt: now` |

## Rules to know

* **`integratorID` is required** — every `create` call must include your own unique `integratorID` for the entry. It is stored on the lead/booking, carried onto the bill when it converts, and echoed back in webhooks so you can match events to your records.
* **Branch scope** — every CRM call needs a `branchID`. Get it from `GET /client/labs`.
* **Duplicates** — if a lead or booking with the same `contact` (or `email`) was already ingested **today** for your account, the API returns `409 Conflict`.
* **Auto-assign** — runs only when `phase = "lead"` and `assignedTo` is not set in the body. Honours the strategy you've configured in CRM settings.
* **Rate limit** — 60 requests/minute per account on every CRM endpoint.

<Note>
  Fields not listed in the request schema are silently ignored. Send only what
  you need.
</Note>
