# Get call analytics

> POST https://api.nabrah.ai/api/ext/call/analytics

Group: Calls. Page: https://www.nabrah.ai/en/docs/api-reference/calls/get-call-analytics

Compute aggregate analytics over historical calls that match a filter. Accepts the same SearchCallsRequest body as the search endpoint, but instead of returning individual call rows it returns summarized analytics for the matching set (counts, durations, status breakdowns, and similar metrics). Use it to power dashboards and reporting over a date range, agent, status, or tag rather than to page through raw calls.

## Filtering

Send only the fields you want to constrain on; omit the rest. All filters are combined (AND). Same body as POST /api/ext/call/search.

- **Time windows**: call_started_at_start / call_started_at_end filter by when the call actually started; created_at_start / created_at_end filter by when the record was created. Use ISO-8601 timestamps. Fields: `call_started_at_start`, `call_started_at_end`, `created_at_start`, `created_at_end`.
- **Scope by agent / number / status**: agent_id restricts to one agent; call_from and call_to filter by phone number; status filters by lifecycle state (queued, ringing, in-progress, completed, failed); call_type filters inbound vs outbound. Fields: `agent_id`, `call_from`, `call_to`, `status`, `call_type`.
- **Tags and free text**: tags matches calls carrying any of the listed tags; tag is a single-tag convenience filter; q is a free-text search across call content. Fields: `tags`, `tag`, `q`.
- **Analysis filters**: analysis_filters constrains by post-call analysis values. Each entry is { name, op, value } where op is a comparison operator such as ==, !=, >, <. Fields: `name`, `op`, `value`.

limit and offset are accepted for parity with search but have no effect on aggregate totals; analytics are computed over the entire matching set.

## Getting an agent_id

To filter by agent, fetch the project's agents first.

- **GET /api/ext/agent**: Lists the agents in your project; use an agent's id as agent_id here.

## Authorization

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

## Body (application/json)

### Example: Minimal

Analytics over a date range with no other constraints.

```json
{
  "created_at_start": "2026-06-01T00:00:00.000Z",
  "created_at_end": "2026-06-23T23:59:59.000Z"
}
```

### Example: Full

All available filters for a single agent's completed outbound calls.

```json
{
  "agent_id": "00000000-0000-4000-8000-000000000000",
  "call_to": "+966500000000",
  "call_from": "+966510000000",
  "call_started_at_start": "2026-06-01T00:00:00.000Z",
  "call_started_at_end": "2026-06-23T23:59:59.000Z",
  "status": "completed",
  "call_type": "outbound",
  "created_at_start": "2026-06-01T00:00:00.000Z",
  "created_at_end": "2026-06-23T23:59:59.000Z",
  "tags": [
    "sales",
    "follow-up"
  ],
  "analysis_filters": [
    {
      "name": "sentiment",
      "op": "==",
      "value": "positive"
    }
  ],
  "tag": "sales",
  "q": "appointment"
}
```

## Response

### 200 Successful Response

Content type: `application/json`

### 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/call/analytics' \
  --header 'X-API-Key: <your-api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
  "created_at_start": "2026-06-01T00:00:00.000Z",
  "created_at_end": "2026-06-23T23:59:59.000Z"
}'
```

### Python

```python
import requests

url = "https://api.nabrah.ai/api/ext/call/analytics"
headers = {
    "X-API-Key": "<your-api-key>",
}
payload = {
    "created_at_start": "2026-06-01T00:00:00.000Z",
    "created_at_end": "2026-06-23T23:59:59.000Z"
}

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/call/analytics", {
  method: "POST",
  headers: {
    "X-API-Key": "<your-api-key>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "created_at_start": "2026-06-01T00:00:00.000Z",
    "created_at_end": "2026-06-23T23:59:59.000Z"
  }),
});

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

### Go

```go
package main

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

func main() {
	payload := strings.NewReader(`{
  "created_at_start": "2026-06-01T00:00:00.000Z",
  "created_at_end": "2026-06-23T23:59:59.000Z"
}`)

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