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

# Purchase numbers

> Buy pool DID(s) with the API-key tenant credits.

Body (one of):

```json theme={"system"}
{ "phoneNumberId": "66f..." }
```

```json theme={"system"}
{ "phoneNumberIds": ["66f...", "66g..."] }
```

Optional: `concurrentCalls` (integer, default `0`), `description`.

**Success `200`**

```json theme={"system"}
{
  "purchased": [
    {
      "id": "66f...",
      "number": "+91xxxxxxxxxx",
      "country": "IN",
      "countryName": "India",
      "status": "purchased",
      "provider": "pool",
      "purchasedAt": "2026-08-26T10:00:00.000Z",
      "cost": 7
    }
  ],
  "totalCost": 7,
  "creditsRemaining": 241780.98
}
```

| Code                        | HTTP | When                                         |
| --------------------------- | ---- | -------------------------------------------- |
| `insufficient_credits`      | 402  | Balance lower than cost — no number assigned |
| `numbers_unavailable`       | 409  | Id invalid or already taken                  |
| `pool_purchase_unavailable` | 422  | Tenant cannot buy pool inventory             |
| `batch_limit_exceeded`      | 400  | More than 20 ids in one request              |

After purchase, create the agent with `phoneNumberId` or E.164 via [Create inbound agent](/api-reference/endpoint/inbound-agents/create-inbound-agent).

See [Healthcare HMS integration](/get-started/guides/healthcare-hms-integration).


## OpenAPI

````yaml openapi.json POST /api/v1/numbers/purchase
openapi: 3.0.3
info:
  title: Ondial Public API
  version: 1.0.0
  description: >-
    Tenant API-key surface for lead ingest, contacts (including dial
    conversation + analysis), events, inbound agents, company profiles, and
    knowledge-base documents.


    **Campaign definition is UI-only** — create and start an API-ingest campaign
    in the dashboard, then push leads here.


    **Auth:** `Authorization: Bearer ond_live_…` or `ond_test_…` (or
    `X-API-Key`). Keys are requested in **API Access** with a friendly **key
    name**, then approved by Super Admin (not self-serve). Tenants can rename
    keys later without rotating the secret.


    **Scopes:** Company and knowledge-base routes require opt-in scopes
    (`companies:read`, `companies:write`, `knowledge:read`, `knowledge:write`)
    granted at key approval. Missing scope → `403 forbidden`.


    **Sandbox** keys never place PSTN dials or live WhatsApp/email and do not
    burn credits (KB upload skips debit).


    **Security:** Company responses never include SMTP/WhatsApp credentials. KB
    v1 is metadata-only — no file download.


    **Kill switch:** Super Admin can disable all `/api/v1/*` (`503` /
    `api_globally_disabled`) without stopping UI CSV campaigns.


    **Compliance:** Call channel requires `consent.outboundCall: true` and phone
    not on tenant/platform DNC.
servers:
  - url: https://dashboard.ondial.ai
    description: Production
  - url: http://localhost:3001
    description: Local
security:
  - BearerAuth: []
tags:
  - name: Core
    description: Auth check and lead ingest
  - name: Contacts
    description: Status, dials/conversation/analysis, cancel, delete, follow-ups, list
  - name: Events
    description: ERP event bus slice — eventType → campaign
  - name: Outbound
    description: >-
      Read-only campaign lookup for API / Custom CRM. Create and start campaigns
      in the dashboard.
  - name: Inbound agents
    description: Configure inbound agents; list/buy pool numbers; read credits
  - name: Companies
    description: >-
      Company profile CRUD (requires companies:read / companies:write scopes).
      Never returns SMTP or WhatsApp credentials.
  - name: Knowledge bases
    description: >-
      Knowledge document upload/list/delete (requires knowledge:read /
      knowledge:write scopes). Metadata only — no file download via API.
paths:
  /api/v1/numbers/purchase:
    post:
      tags:
        - Inbound agents
      summary: Purchase pool numbers
      description: >-
        Buy one or more pool DIDs for the API-key tenant. Debits credits
        atomically. Max 20 per request. Twilio/Telnyx purchase is not supported
        on this route.
      operationId: purchaseNumbers
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                phoneNumberId:
                  type: string
                  description: Single catalog id from GET /numbers/available
                phoneNumberIds:
                  type: array
                  items:
                    type: string
                  maxItems: 20
                  description: Batch of catalog ids
                concurrentCalls:
                  type: integer
                  default: 0
                description:
                  type: string
            example:
              phoneNumberId: 66f0123456789abcdef01234
      responses:
        '200':
          description: Purchase succeeded
          content:
            application/json:
              schema:
                type: object
                properties:
                  purchased:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        number:
                          type: string
                        country:
                          type: string
                        countryName:
                          type: string
                        status:
                          type: string
                        provider:
                          type: string
                        purchasedAt:
                          type: string
                          format: date-time
                        cost:
                          type: number
                  totalCost:
                    type: number
                  creditsRemaining:
                    type: number
              example:
                purchased:
                  - id: 66f0123456789abcdef01234
                    number: '+919876543210'
                    country: IN
                    countryName: India
                    status: purchased
                    provider: pool
                    purchasedAt: '2026-08-26T10:00:00.000Z'
                    cost: 7
                totalCost: 7
                creditsRemaining: 241780.98
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
              example:
                error: phoneNumberId or phoneNumberIds required
                reasonCode: invalid_request
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: Insufficient credits
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
              example:
                error: Insufficient credits. Need 7, have 2.00.
                reasonCode: insufficient_credits
                requiredCredits: 7
                creditsAvailable: 2
        '409':
          description: Numbers unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
              example:
                error: Some numbers are no longer available
                reasonCode: numbers_unavailable
                unavailablePhoneNumberIds:
                  - '000000000000000000000000'
        '422':
          description: Pool purchase unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
              example:
                error: Pool number purchase is not enabled for this account.
                reasonCode: pool_purchase_unavailable
components:
  schemas:
    ErrorBody:
      type: object
      properties:
        error:
          type: string
        reasonCode:
          type: string
        missing:
          type: array
          items:
            type: string
  responses:
    Unauthorized:
      description: Missing, invalid, or inactive API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBody'
          example:
            error: Invalid or inactive API key
            reasonCode: unauthorized
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: ond_live | ond_test
      description: >-
        Paste only your API key (`ond_live_…` or `ond_test_…`). Do not type the
        word Bearer — the playground adds it.

````