# Link an agent to an inbound trunk

> POST https://api.nabrah.ai/api/ext/agent-inbound-link

Group: Agent inbound links. Page: https://www.nabrah.ai/en/docs/api-reference/agent-inbound-links/link-an-agent-to-an-inbound-trunk

Links an agent to a SIP inbound trunk so the agent answers calls arriving on that trunk. Both the agent and the trunk must already exist in the workspace behind your API key — create them with POST /api/ext/agent and POST /api/ext/sip-inbound. Save the returned `link_id` to de-link later via DELETE /api/ext/agent-inbound-link/{link_id}.

## Where the IDs come from

- **agent_id and inbound_id**: `agent_id` comes from GET /api/ext/agent or the create response of POST /api/ext/agent. `inbound_id` comes from GET /api/ext/sip-inbound or the create response of POST /api/ext/sip-inbound. Fields: `agent_id`, `inbound_id`.

## When this returns 400

All three of these produce the same 400 response, so check them in order.

- **Agent or trunk not in this workspace**: Both IDs are validated against the workspace behind your API key. An ID belonging to another workspace is rejected exactly like a non-existent one.
- **The link already exists**: The same agent cannot be linked to the same trunk twice. Call GET /api/ext/agent-inbound-link first if you need to know whether a pair is already linked.

## Many-to-many

- **Several agents on one trunk**: A trunk may carry several agents and an agent may serve several trunks — call this endpoint once per pair. Which agent answers a given call is decided at call time by the voice runtime, not by this API.

## Authorization

- `X-API-Key` (string, header, required): your workspace API key.

## Body (application/json)

### Example: Link agent to trunk

Attach one agent to one SIP inbound trunk.

```json
{
  "agent_id": "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d4e5f",
  "inbound_id": "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d5a60"
}
```

## Response

### 200 Successful Response

Content type: `application/json`

```json
{
  "link_id": "00000000-0000-4000-8000-000000000000",
  "agent": {
    "agent_id": "00000000-0000-4000-8000-000000000000",
    "name": "string"
  },
  "sip_inbound": {
    "id": "00000000-0000-4000-8000-000000000000",
    "numbers": "string"
  },
  "project_id": "00000000-0000-4000-8000-000000000000",
  "created_at": "2026-01-15T12:00:00.000Z"
}
```

### 422 Validation Error

Content type: `application/json`

```json
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

## Request examples

### cURL

```bash
curl --request POST \
  --url 'https://api.nabrah.ai/api/ext/agent-inbound-link' \
  --header 'X-API-Key: <your-api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
  "agent_id": "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d4e5f",
  "inbound_id": "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d5a60"
}'
```

### Python

```python
import requests

url = "https://api.nabrah.ai/api/ext/agent-inbound-link"
headers = {
    "X-API-Key": "<your-api-key>",
}
payload = {
    "agent_id": "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d4e5f",
    "inbound_id": "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d5a60"
}

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

### JavaScript

```javascript
const response = await fetch("https://api.nabrah.ai/api/ext/agent-inbound-link", {
  method: "POST",
  headers: {
    "X-API-Key": "<your-api-key>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "agent_id": "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d4e5f",
    "inbound_id": "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d5a60"
  }),
});

const data = await response.json();
console.log(data);
```

### Go

```go
package main

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

func main() {
	payload := strings.NewReader(`{
  "agent_id": "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d4e5f",
  "inbound_id": "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d5a60"
}`)

	req, _ := http.NewRequest("POST", "https://api.nabrah.ai/api/ext/agent-inbound-link", payload)
	req.Header.Set("X-API-Key", "<your-api-key>")
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	out, _ := io.ReadAll(res.Body)
	fmt.Println(string(out))
}
```
