# Link agents to an analysis group

> POST https://api.nabrah.ai/api/ext/analysis/{analysis_group_id}/agents

Group: Analysis groups. Page: https://www.nabrah.ai/en/docs/api-reference/analysis-groups/link-agents-to-an-analysis-group

Links multiple agents to the analysis group identified by `analysis_group_id` in a single call and returns one `link_id` per created link. Use this to attach a batch of existing agents to the same analysis group at once. The agents must already exist (create them with POST /api/ext/agent).

## Where the IDs come from

- **Path and body IDs**: `analysis_group_id` (path) comes from GET /api/ext/analysis. Each value in `agent_ids` comes from GET /api/ext/agent.

## Response shape

- **link_ids array**: Returns `{ "link_ids": [...] }` — one ID per agent linked. Use any with DELETE /api/ext/analysis/link/{link_id} to remove a specific link. For a single agent, POST /api/ext/analysis/{analysis_group_id}/agent is simpler. Fields: `link_ids`.

## Authorization

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

## Path parameters

- `analysis_group_id` (string, required): UUID of the analysis group to link agents to. Get this from GET /api/ext/analysis or from the create response (POST /api/ext/analysis).

## Body (application/json)

### Example: Link agents

Link several agents to this analysis group in one request.

```json
{
  "agent_ids": [
    "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d4e5f",
    "018f3a2b-8b3c-7e1a-bf52-0a1b2c3d4e5f"
  ]
}
```

## Response

### 200 Successful Response

Content type: `application/json`

```json
{
  "link_ids": [
    "00000000-0000-4000-8000-000000000000"
  ]
}
```

### 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/analysis/<analysis_group_id>/agents' \
  --header 'X-API-Key: <your-api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
  "agent_ids": [
    "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d4e5f",
    "018f3a2b-8b3c-7e1a-bf52-0a1b2c3d4e5f"
  ]
}'
```

### Python

```python
import requests

url = "https://api.nabrah.ai/api/ext/analysis/<analysis_group_id>/agents"
headers = {
    "X-API-Key": "<your-api-key>",
}
payload = {
    "agent_ids": [
        "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d4e5f",
        "018f3a2b-8b3c-7e1a-bf52-0a1b2c3d4e5f"
    ]
}

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/analysis/<analysis_group_id>/agents", {
  method: "POST",
  headers: {
    "X-API-Key": "<your-api-key>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "agent_ids": [
      "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d4e5f",
      "018f3a2b-8b3c-7e1a-bf52-0a1b2c3d4e5f"
    ]
  }),
});

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

### Go

```go
package main

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

func main() {
	payload := strings.NewReader(`{
  "agent_ids": [
    "018f3a2b-9c4d-7e1a-bf52-0a1b2c3d4e5f",
    "018f3a2b-8b3c-7e1a-bf52-0a1b2c3d4e5f"
  ]
}`)

	req, _ := http.NewRequest("POST", "https://api.nabrah.ai/api/ext/analysis/<analysis_group_id>/agents", 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))
}
```
