# Analytics reference

> Every Analytics endpoint with parameters, request and response fields, required scope and a curl example.

Every Analytics endpoint. Base URL `https://api.pingx.ai`; send `Authorization: Bearer <API key>`. Read endpoints need `analytics:read` (or `:write`), write endpoints need `analytics:write`; the bare `analytics` scope grants both. See [Authentication and conventions](https://docs.pingx.ai/authentication.md). Machine-readable: [openapi.json](/openapi.json).

**4 endpoints**

| Method | Path | Operation | Scope |
|---|---|---|---|
| `GET` | `/analytics/v1/branch-leaderboard` | GetBranchLeaderboard | read |
| `GET` | `/analytics/v1/call-volume` | GetCallVolume | read |
| `GET` | `/analytics/v1/custom-metrics` | GetCustomMetrics | read |
| `GET` | `/analytics/v1/nps-trend` | GetNpsTrend | read |

## GET /analytics/v1/branch-leaderboard

**GetBranchLeaderboard** · needs `analytics:read` (or write)

Returns every branch's NPS over the whole lookback window (not per day),
best NPS first, with its response and detractor counts. Use it to find
the best and worst performing branches/locations. Read-only and
idempotent.

**Query parameters**

| Name | Type | Description |
|---|---|---|
| `days` | integer | Lookback window in calendar days ending today (inclusive). <= 0 means 30; maximum 180 (larger values are clamped). |

**Response** `GetBranchLeaderboardResponse`

| Field | Type | Description |
|---|---|---|
| `rows` | BranchLeaderboardRow[] | Branches, best NPS first. |
| `rows[].branch` | string | Branch (location) name as recorded on the survey responses. |
| `rows[].nps` | number | NPS over the whole lookback window (not per day), from -100 to 100. |
| `rows[].responses` | integer | Number of NPS responses in the window. |
| `rows[].detractors` | integer | Number of detractor responses in the window. |
| `days` | integer | The effective lookback window in days after defaulting/clamping. |

```bash
curl "https://api.pingx.ai/analytics/v1/branch-leaderboard" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## GET /analytics/v1/call-volume

**GetCallVolume** · needs `analytics:read` (or write)

Returns how many calls were placed and how many completed in the last
"days" days. Read-only and idempotent. For individual calls use the
voice API.

**Query parameters**

| Name | Type | Description |
|---|---|---|
| `days` | integer | Lookback window in calendar days ending today (inclusive). <= 0 means 30; maximum 180 (larger values are clamped). |

**Response** `GetCallVolumeResponse`

| Field | Type | Description |
|---|---|---|
| `callsPlaced` | integer | Calls placed (attempted) in the window, across AI personas, human operators and feedback calls. |
| `callsDone` | integer | Calls that completed in the window. |
| `days` | integer | The effective lookback window in days after defaulting/clamping. |

```bash
curl "https://api.pingx.ai/analytics/v1/call-volume" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## GET /analytics/v1/custom-metrics

**GetCustomMetrics** · needs `analytics:read` (or write)

Returns the organization's custom metrics: numeric fields the AI
extracts from every call according to the organization's custom-field
configuration (for example "customer satisfaction 1-5"), as daily
average series per AI agent (persona) or for human operators, together
with AI-generated "what is working / what is not" insights where enough
calls exist. Filter to one agent with agentId, or to human operators
with humanOperatorsOnly. Read-only and idempotent.

**Query parameters**

| Name | Type | Description |
|---|---|---|
| `days` | integer | Lookback window in calendar days ending today (inclusive). <= 0 means 30; maximum 180 (larger values are clamped). |
| `agentId` | string (int64) | Restrict to the series produced by one AI agent (persona). The id comes from the agents API. 0 (default) means every scope ("all personas"). |
| `humanOperatorsOnly` | boolean | When true, restrict to the series produced for human operators (calls handled by people rather than AI agents). |

**Response** `GetCustomMetricsResponse`

| Field | Type | Description |
|---|---|---|
| `series` | CustomMetricSeries[] | One series per (scope, custom field). |
| `series[].scopeType` | string | Which kind of caller produced the values: "agent" or "human_operators". |
| `series[].agentName` | string | AI agent (persona) name; empty for human operators. |
| `series[].fieldKey` | string | Stable machine key of the custom field, e.g. "csat". |
| `series[].fieldLabel` | string | Human-readable label of the custom field, e.g. "Customer satisfaction". |
| `series[].minValue` | integer | Lowest value the field can take (scale lower bound). |
| `series[].maxValue` | integer | Highest value the field can take (scale upper bound). |
| `series[].points` | CustomMetricPoint[] | Daily average values, oldest first. |
| `series[].insightGood` | string[] | AI-written bullets on what is working well. Empty when no insight has been generated yet or the sample is below the threshold. |
| `series[].insightBad` | string[] | AI-written bullets on what is not going well. Same emptiness rule. |
| `series[].insightGeneratedAt` | string | When the insight was generated, RFC 3339; empty when none exists yet. |
| `series[].insightSampleSize` | integer | Number of calls the insight was (or would be) computed from; 0 when no insight exists yet. |
| `days` | integer | The effective lookback window in days after defaulting/clamping. |

```bash
curl "https://api.pingx.ai/analytics/v1/custom-metrics" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## GET /analytics/v1/nps-trend

**GetNpsTrend** · needs `analytics:read` (or write)

Returns the organization's Net Promoter Score (NPS) as a daily time
series for the last "days" days, aggregated across all branches, oldest
day first. NPS ranges from -100 to 100 (percent promoters minus percent
detractors). Days with no survey responses are reported with
responses = 0 and nps = 0; check "responses" before treating an nps of 0
as a real score. Read-only and idempotent.

**Query parameters**

| Name | Type | Description |
|---|---|---|
| `days` | integer | Lookback window in calendar days ending today (inclusive). <= 0 means 30; maximum 180 (larger values are clamped). |

**Response** `GetNpsTrendResponse`

| Field | Type | Description |
|---|---|---|
| `points` | NpsTrendPoint[] | Daily points, oldest first. |
| `points[].date` | string | The day, as an RFC 3339 timestamp (day granularity). |
| `points[].nps` | number | Net Promoter Score for that day aggregated across all branches, from -100 to 100. 0 when responses = 0 (no data) — check "responses" first. |
| `points[].responses` | integer | Number of NPS survey responses collected that day across all branches. |
| `days` | integer | The effective lookback window in days after defaulting/clamping. |

```bash
curl "https://api.pingx.ai/analytics/v1/nps-trend" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```


