# Create analysis group

> POST https://api.nabrah.ai/api/ext/analysis

Group: Analysis groups. Page: https://www.nabrah.ai/en/docs/api-reference/analysis-groups/create-analysis-group

Creates a new analysis group together with its data collections and returns the full group, including the generated `id`. Each data collection describes one piece of information to extract or evaluate from a call — a `name`, a `type`, a human-readable `description`, and optional `constraints`. After creating a group, link it to one or more agents (via POST /api/ext/agent/{agent_id}/analysis_groups or POST /api/ext/analysis/{analysis_group_id}/agent(s)) so it runs after those agents' calls.

## Body fields

- **Group and data collections**: `name` labels the group. `data_collections` is the list of items to capture; each has a `name` (the field key), a `type` (the expected data type, e.g. "string", "number", "boolean"), a `description` guiding what to extract/evaluate, and an optional `constraints` object for additional rules. Fields: `name`, `data_collections`.

## Order of operations

- **Then link to agents**: Creating a group does not attach it to any agent. After capturing the returned `id`, link it using the agent or analysis linking endpoints.

A 422 response means the body failed validation; inspect `detail` for the offending field path.

## Authorization

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

## Body (application/json)

### Example: Minimal

A group with a single extraction field.

```json
{
  "name": "Call Outcome",
  "data_collections": [
    {
      "name": "resolved",
      "type": "boolean",
      "description": "Whether the caller's issue was resolved during the call.",
      "constraints": {}
    }
  ]
}
```

### Example: Full

A group with multiple data collections of different types.

```json
{
  "name": "Support Call Analysis",
  "data_collections": [
    {
      "name": "resolved",
      "type": "boolean",
      "description": "Whether the caller's issue was resolved during the call.",
      "constraints": {}
    },
    {
      "name": "sentiment",
      "type": "string",
      "description": "Overall caller sentiment at the end of the call.",
      "constraints": {
        "enum": [
          "positive",
          "neutral",
          "negative"
        ]
      }
    },
    {
      "name": "satisfaction_score",
      "type": "number",
      "description": "Estimated caller satisfaction on a 1-5 scale.",
      "constraints": {
        "min": 1,
        "max": 5
      }
    }
  ]
}
```

## Response

### 200 Successful Response

Content type: `application/json`

```json
{
  "name": "string",
  "id": "00000000-0000-4000-8000-000000000000",
  "project_id": "00000000-0000-4000-8000-000000000000",
  "created_at": "2026-01-15T12:00:00.000Z",
  "updated_at": "2026-01-15T12:00:00.000Z",
  "data_collections": [
    {
      "name": "string",
      "type": "string",
      "id": "00000000-0000-4000-8000-000000000000",
      "analysis_group_id": "00000000-0000-4000-8000-000000000000",
      "description": "string",
      "constraints": {}
    }
  ]
}
```

### 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' \
  --header 'X-API-Key: <your-api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "Call Outcome",
  "data_collections": [
    {
      "name": "resolved",
      "type": "boolean",
      "description": "Whether the caller'\''s issue was resolved during the call.",
      "constraints": {}
    }
  ]
}'
```

### Python

```python
import requests

url = "https://api.nabrah.ai/api/ext/analysis"
headers = {
    "X-API-Key": "<your-api-key>",
}
payload = {
    "name": "Call Outcome",
    "data_collections": [
        {
            "name": "resolved",
            "type": "boolean",
            "description": "Whether the caller's issue was resolved during the call.",
            "constraints": {}
        }
    ]
}

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", {
  method: "POST",
  headers: {
    "X-API-Key": "<your-api-key>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "Call Outcome",
    "data_collections": [
      {
        "name": "resolved",
        "type": "boolean",
        "description": "Whether the caller's issue was resolved during the call.",
        "constraints": {}
      }
    ]
  }),
});

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

### Go

```go
package main

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

func main() {
	payload := strings.NewReader(`{
  "name": "Call Outcome",
  "data_collections": [
    {
      "name": "resolved",
      "type": "boolean",
      "description": "Whether the caller's issue was resolved during the call.",
      "constraints": {}
    }
  ]
}`)

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