> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.messageblue.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.messageblue.ai/_mcp/server.

# Assign an agent phone number to an account

POST https://api.messageblue.ai/agents/{phoneNumber}/assign
Content-Type: application/json

Maps the agent to the authenticated account so it appears in GET /agents. Fails with 409 if the agent is already owned by a different account. The agent does not need to be online to be assigned, but it must register/connect to show as online.

Reference: https://docs.messageblue.ai/api-reference/agents/assign-agent-to-account

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: swagger
  version: 1.0.0
paths:
  /agents/{phoneNumber}/assign:
    post:
      operationId: assignAgentToAccount
      summary: Assign an agent phone number to an account
      description: >-
        Maps the agent to the authenticated account so it appears in GET
        /agents. Fails with 409 if the agent is already owned by a different
        account. The agent does not need to be online to be assigned, but it
        must register/connect to show as online.
      tags:
        - agents
      parameters:
        - name: phoneNumber
          in: path
          required: true
          schema:
            type: string
        - name: X-App-Id
          in: header
          description: >-
            Your MessageBlue App ID, sent in clear on every request. It is
            paired with request signing: each request is also signed with your
            App Secret (see the **Authentication** tag). The App Secret itself
            is NEVER transmitted — it is only the HMAC signing key.
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Agent assigned to account
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentAssignResponse'
        '400':
          description: Invalid phone number format
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: accountId does not match the authenticated account
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: Agent already owned by another account
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Failed to assign agent
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentAssignRequest'
servers:
  - url: https://api.messageblue.ai
    description: Production
  - url: http://localhost:8080
    description: Local development
components:
  schemas:
    AgentAssignRequest:
      type: object
      properties:
        appId:
          type: string
          description: >-
            Optional app ID used to build attachment storage paths for this
            agent's inbound media. Defaults to the authenticated X-App-Id.
      title: AgentAssignRequest
    AgentStatus:
      type: string
      enum:
        - online
        - offline
        - blocked
      title: AgentStatus
    AgentInfoMeta:
      type: object
      properties: {}
      title: AgentInfoMeta
    AgentInfo:
      type: object
      properties:
        number:
          type: string
        machineId:
          type: string
        lastSeen:
          type: number
          format: double
        status:
          $ref: '#/components/schemas/AgentStatus'
        blocked:
          type: boolean
        blockedReason:
          type:
            - string
            - 'null'
        blockedAt:
          type:
            - number
            - 'null'
          format: double
        meta:
          $ref: '#/components/schemas/AgentInfoMeta'
        registeredAt:
          type:
            - number
            - 'null'
          format: double
        gatewayInstance:
          type:
            - string
            - 'null'
        accountId:
          type:
            - string
            - 'null'
      title: AgentInfo
    AgentAssignResponseData:
      type: object
      properties:
        phoneNumber:
          type: string
        accountId:
          type: string
        claimed:
          type: boolean
          description: True when ownership was newly claimed for this account
        alreadyAssigned:
          type: boolean
          description: True when the agent was already owned by this account
        agent:
          $ref: '#/components/schemas/AgentInfo'
      required:
        - phoneNumber
        - accountId
      description: Endpoint-specific payload wrapped in a standard success envelope.
      title: AgentAssignResponseData
    ResponseMeta:
      type: object
      properties:
        requestId:
          type: string
          format: uuid
        timestamp:
          type: string
          format: date-time
      required:
        - requestId
        - timestamp
      title: ResponseMeta
    AgentAssignResponse:
      type: object
      properties:
        ok:
          type: boolean
        data:
          $ref: '#/components/schemas/AgentAssignResponseData'
          description: Endpoint-specific payload wrapped in a standard success envelope.
        meta:
          $ref: '#/components/schemas/ResponseMeta'
      required:
        - ok
        - data
        - meta
      title: AgentAssignResponse
    FieldError:
      type: object
      properties:
        field:
          type: string
        issue:
          type: string
        message:
          type: string
      required:
        - field
        - issue
        - message
      title: FieldError
    ErrorResponseErrorDetails0:
      type: array
      items:
        $ref: '#/components/schemas/FieldError'
      title: ErrorResponseErrorDetails0
    ErrorResponseErrorDetails:
      oneOf:
        - $ref: '#/components/schemas/ErrorResponseErrorDetails0'
        - type: object
          additionalProperties:
            description: Any type
      description: Field validation errors (array) or domain-specific context (object).
      title: ErrorResponseErrorDetails
    ErrorResponseError:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
        requestId:
          type: string
          format: uuid
        details:
          $ref: '#/components/schemas/ErrorResponseErrorDetails'
          description: Field validation errors (array) or domain-specific context (object).
      required:
        - code
        - message
        - requestId
      title: ErrorResponseError
    ErrorResponse:
      type: object
      properties:
        ok:
          type: boolean
        error:
          $ref: '#/components/schemas/ErrorResponseError'
      required:
        - ok
        - error
      title: ErrorResponse
  securitySchemes:
    appId:
      type: apiKey
      in: header
      name: X-App-Id
      description: >-
        Your MessageBlue App ID, sent in clear on every request. It is paired
        with request signing: each request is also signed with your App Secret
        (see the **Authentication** tag). The App Secret itself is NEVER
        transmitted — it is only the HMAC signing key.

```

## Examples



**Request**

```json
{}
```

**Response**

```json
{
  "ok": true,
  "data": {
    "phoneNumber": "+14155550123",
    "accountId": "string",
    "claimed": true,
    "alreadyAssigned": true,
    "agent": {
      "number": "string",
      "machineId": "string",
      "lastSeen": 1.1,
      "status": "online",
      "blocked": true,
      "blockedReason": "string",
      "blockedAt": 1.1,
      "meta": {},
      "registeredAt": 1.1,
      "gatewayInstance": "string",
      "accountId": "string"
    }
  },
  "meta": {
    "requestId": "550e8400-e29b-41d4-a716-446655440000",
    "timestamp": "2026-07-10T06:00:00.000Z"
  }
}
```

**SDK Code**

```python Agents_assignAgentToAccount_example
import requests

url = "https://api.messageblue.ai/agents/%2B14155550123/assign"

payload = {}
headers = {
    "X-App-Id": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Agents_assignAgentToAccount_example
const url = 'https://api.messageblue.ai/agents/%2B14155550123/assign';
const options = {
  method: 'POST',
  headers: {'X-App-Id': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Agents_assignAgentToAccount_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.messageblue.ai/agents/%2B14155550123/assign"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-App-Id", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Agents_assignAgentToAccount_example
require 'uri'
require 'net/http'

url = URI("https://api.messageblue.ai/agents/%2B14155550123/assign")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-App-Id"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{}"

response = http.request(request)
puts response.read_body
```

```java Agents_assignAgentToAccount_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.messageblue.ai/agents/%2B14155550123/assign")
  .header("X-App-Id", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php Agents_assignAgentToAccount_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.messageblue.ai/agents/%2B14155550123/assign', [
  'body' => '{}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-App-Id' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Agents_assignAgentToAccount_example
using RestSharp;

var client = new RestClient("https://api.messageblue.ai/agents/%2B14155550123/assign");
var request = new RestRequest(Method.POST);
request.AddHeader("X-App-Id", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Agents_assignAgentToAccount_example
import Foundation

let headers = [
  "X-App-Id": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.messageblue.ai/agents/%2B14155550123/assign")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```