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

# Assign Phone Number

Assign a phone number to an agent. This enables the agent to handle inbound calls to this number.

<Note>
  For Twilio phone numbers, this endpoint automatically configures the webhook URLs in Twilio.
</Note>

### Headers

<ParamField header="X-API-Key" type="string" required>
  Your API key for authentication.
</ParamField>

<ParamField header="X-Organization-Id" type="string" required>
  The organization ID.
</ParamField>

<ParamField header="Content-Type" type="string" required>
  Must be `application/json`.
</ParamField>

### Path Parameters

<ParamField path="agent_id" type="string" required>
  The unique identifier of the agent.
</ParamField>

### Request Body

<ParamField body="phone_number_id" type="string" required>
  The unique identifier of the phone number to assign (format: `phon_[a-f0-9]{12,}`).
</ParamField>

### Permissions

* `phone_numbers:update` (admin, agent\_manager)

### Response

<ResponseField name="success" type="boolean">
  Indicates if the assignment was successful.
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable success message.
</ResponseField>

<ResponseField name="data" type="object">
  The updated agent object.
</ResponseField>

<RequestExample>
  ```json Request theme={null}
  {
    "phone_number_id": "phon_b2c3d4e5f6a7"
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "success": true,
    "message": "Phone number assigned successfully",
    "data": {
      "agent_id": "agent_a1b2c3d4e5f6",
      "agent_name": "Sales Rep",
      "assigned_phone_number_ids": ["phon_b2c3d4e5f6a7"],
      "updated_at": "2024-01-20T14:45:00Z"
    }
  }
  ```
</ResponseExample>

### Errors

<ResponseField name="404" type="object">
  Agent or phone number not found.
</ResponseField>

<ResponseField name="403" type="object">
  Access denied to agent or phone number belongs to different organization.
</ResponseField>

<ResponseField name="409" type="object">
  Phone number already assigned to another agent, or already assigned to this agent.
</ResponseField>

<ResponseField name="400" type="object">
  Phone number has no associated integration (for Twilio numbers).
</ResponseField>
