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

# Import Phone Number

> Import or attach a phone number to an agent through the frontend API.

Imports a phone number from Twilio to use with an agent.

### Request

**Method:** `POST`\
**Endpoint:** `/api/import-number`\
**Headers:**

* `X-Authorization`: Your API key (required)
* `Content-Type`: `application/json`

**Request Body:**

```json theme={null}
{
  "uid": "string",
  "agentId": "string",
  "source": "string",
  "twilioAccountSid": "string",
  "twilioAuthToken": "string",
  "phoneNumber": "string",
  "countryCode": "string"
}
```

**Parameters:**

* `uid` (string, required): Your user ID
* `agentId` (string, required): The ID of the agent to assign the phone number to
* `source` (string, required): Must be "twilio" (only Twilio is currently supported)
* `twilioAccountSid` (string, required): Your Twilio Account SID
* `twilioAuthToken` (string, required): Your Twilio Auth Token
* `phoneNumber` (string, required): The phone number to import
* `countryCode` (string, required): The country code for the phone number

### Response

**Success Response (200):**

```json theme={null}
{
  "message": "string"
}
```

**Error Responses:**

* `400 Bad Request`: Invalid request body, invalid source, or agent already has a phone number
* `401 Unauthorized`: Invalid or missing API key, or insufficient permissions
* `500 Internal Server Error`: Agent not found, user needs paid plan, or server error

### Example

```bash theme={null}
curl -X POST https://app.phonely.ai/api/import-number \
  -H "X-Authorization: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "uid": "user123",
    "agentId": "agent456",
    "source": "twilio",
    "twilioAccountSid": "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "twilioAuthToken": "your-twilio-auth-token",
    "phoneNumber": "+1234567890",
    "countryCode": "US"
  }'
```

### Notes

* Only Twilio phone numbers are currently supported
* The agent must be on a paid plan to import phone numbers
* The agent cannot already have a business phone number assigned
* This operation has a maximum duration of 60 seconds


## OpenAPI

````yaml POST /import-number
openapi: 3.0.1
info:
  title: Phonely API
  description: API for Phonely services including agent management and call summaries
  version: 1.0.0
servers:
  - url: https://app.phonely.ai/api
security: []
paths:
  /import-number:
    post:
      summary: Import number
      description: Import a Twilio phone number to an agent
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImportNumberRequest'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImportNumberResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    ImportNumberRequest:
      type: object
      required:
        - uid
        - agentId
        - source
        - twilioAccountSid
        - twilioAuthToken
        - phoneNumber
        - countryCode
      properties:
        uid:
          type: string
          description: User ID
        agentId:
          type: string
          description: Agent ID (agent should not have a phone number assigned yet)
        source:
          type: string
          description: Phone number source (currently only supports 'twilio')
        twilioAccountSid:
          type: string
          description: Twilio account SID
        twilioAuthToken:
          type: string
          description: Twilio auth token
        phoneNumber:
          type: string
          description: Phone number to import, includes country code. i.e +10123456789
        countryCode:
          type: string
          description: Country code of the phone number, ISO 3166-1 alpha-2 format
    ImportNumberResponse:
      type: object
      properties:
        message:
          type: string
          description: Message indicating the result of the operation
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error code or identifier
        message:
          type: string
          description: Detailed error message
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Authorization

````