# Per-template engagement rollup

`GET /v1/reports/template-performance`

- Authentication: required (Bearer token)
- Required scope: `reports.view`

One row per template aggregating activity across the entire query
window — no time bucketing. Use this to spot templates that bounce
more, complain more, or under-engage compared to peers. Rows are
sorted by `sent` descending, tie-broken by `template` ascending. Sends
that aren't tied to a named template (raw `SendEmail` calls without a
`Template` parameter) are excluded so they don't dominate the
ranking.

Rate formulas (note the **asymmetric** denominators, matching the
dashboard):

- `bounce_rate = bounced / sent`
- `complaint_rate = complained / sent`
- `open_rate = unique_opens / delivered`
- `click_rate = unique_clicks / delivered`

All ratios are in `[0, 1]`. Zero denominators yield `0.0`. The
`template` field is the SES template name (the slug — the value SES
received in the `Template` parameter), not a UI display name.

Default window is the trailing 30 days; plan retention applies. No
pagination — the response holds every template the org used in the
window.

## Query parameters

- `from` (string<date-time>, optional) — Window start (RFC 3339). Defaults to 30 days ago.
- `to` (string<date-time>, optional) — Window end (RFC 3339). Defaults to now.
- `channel` (string<uuid>, optional) — Filter by channel UUID. Malformed values return `422 validation_failed`.
- `identity` (string, optional) — Filter by sending identity. Accepts a full email address (the
local-part is ignored — only the domain matches) or a bare domain.
- `template` (string, optional) — Case-insensitive exact match on template name. Useful when you
only want one template's row. A non-matching value returns
`200` with `data: []`, not `404`.

## Example request

```bash
curl 'https://api.sendops.dev/v1/reports/template-performance' \
  -H "Authorization: Bearer $SENDOPS_API_KEY"
```

## Responses

### 200 — Per-template rows, sorted by sends descending

Content type: `application/json`

```json
{
  "data": [
    {
      "template": "string",
      "sent": 0,
      "delivered": 0,
      "opens": 0,
      "unique_opens": 0,
      "clicks": 0,
      "unique_clicks": 0,
      "bounced": 0,
      "complained": 0,
      "bounce_rate": 0,
      "complaint_rate": 0,
      "open_rate": 0,
      "click_rate": 0
    }
  ]
}
```

### 401 — Missing, malformed, or unknown API key

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ]
}
```

### 403 — Key lacks the required scope or plan limit violated

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ]
}
```

### 422 — Query parameter or path value failed validation

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ]
}
```

### 429 — Per-org rate limit exceeded

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ]
}
```

### 500 — Unexpected server-side failure. The `code` is `internal_error`. The
`request_id` field can be quoted to SendOps support to investigate.

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ]
}
```
