# YouTube Analytics Report (`youtube.analytics_report`)

Runs a YouTube Analytics report for your channel: views, watch time, subscribers and engagement by day, video, country, traffic source, device or audience.

Docs: https://primaryapi.com/docs/api-reference/youtube/analytics_report

- Endpoint: `POST https://api.primaryapi.com/v1/run/youtube.analytics_report`
- Category: Web Intelligence · Platform: `youtube` · Kind: search · Status: live
- Price: 1 credit per call. Every call costs the same, including calls that were retried automatically.
- Billing unit: per successful call
- Reliability: routed to a healthy upstream and retried automatically when an attempt fails; live 30-day status: `GET https://api.primaryapi.com/v1/status/apis?sku=youtube.analytics_report`
- Execution: synchronous (answers 202 only if it outlives the wait window)

## Input

| Field | Type | Required | Default | Constraints | Description |
|---|---|---|---|---|---|
| `channelId` | string | no |  | pattern: ^[A-Za-z0-9_-]{1,64}$ | One of your channel ids (youtube.my_channels). Default: the channel of the connected account ("MINE"). |
| `startDate` | string | yes |  | pattern: ^\d{4}-\d{2}-\d{2}$ | First day of the report (YYYY-MM-DD), inclusive. |
| `endDate` | string | yes |  | pattern: ^\d{4}-\d{2}-\d{2}$ | Last day of the report (YYYY-MM-DD), inclusive; on or after startDate. |
| `metrics` | string[] | yes |  | min 1 items; max 20 items | Metrics (1-20), e.g. ["views", "estimatedMinutesWatched", "subscribersGained"]. Revenue and ad metrics need youtube.revenue_report. |
| `dimensions` | enum[] | no | [] | max 6 items | Group rows by these (up to 6), e.g. ["day"], ["video"], ["country"], ["ageGroup", "gender"]. Empty (default) = one total row. |
| `filters` | object[] | no |  | max 10 items | Filters that must all match, e.g. [{"dimension":"video","values":["dQw4w9WgXcQ"]}]. |
| `filters[].dimension` | enum | yes |  | one of: video, playlist, country, province, dma, city, day, month, insightPlaybackLocationType, insightPlaybackLocationDetail, creatorContentType, liveOrOnDemand, subscribedStatus, youtubeProduct, insightTrafficSourceType, insightTrafficSourceDetail, deviceType, operatingSystem, ageGroup, gender, sharingService, elapsedVideoTimeRatio, audienceType, livestreamPosition, membershipsCancellationSurveyReason, adType, reservedInstreamSelect, continent, subContinent, group, isCurated | Dimension to filter on, e.g. "video", "country", "continent", "insightTrafficSourceType". |
| `filters[].values` | string[] | yes |  | min 1 items; max 500 items; items pattern: ^[^=,;]{1,200}$ | Values to keep. Several values only for video and playlist (up to 500 ids). |
| `sort` | object[] | no |  | max 5 items | Sort order, e.g. [{"field":"views","descending":true}]. Top-video and detail reports require one. |
| `sort[].field` | string | yes |  | max 100 chars | A metric or dimension of this report. |
| `sort[].descending` | boolean | no | false |  | Descending order (default ascending). |
| `limit` | integer | no | 200 | 1–10000 | Maximum number of results to return (1-10000, default 200). |
| `cursor` | string | no |  |  | Opaque pagination cursor: pass the previous response's nextCursor. |
| `connection` | string | no |  | max 200 chars | Which connected account to use when the workspace has several for this provider: the customId you gave it (exact), its connection id ("con_…"), its handle (login, email or @handle) or its name. Optional; prefer the customId or id, which never match two accounts. |

Unknown fields are rejected with `400 invalid_input`. The routing controls `preferLatencyUnderMs` and `maxCredits` may be sent in the same JSON body.

## Output

When `output.found` is `true`, `output.data` has this shape:

| Field | Type | Description |
|---|---|---|
| `rows` | object[] | One object per row, keyed by dimension and metric name |
| `columnHeaders` | object[] |  |
| `columnHeaders[].name` | string |  |
| `columnHeaders[].columnType` | string \| null | DIMENSION or METRIC |
| `columnHeaders[].dataType` | string \| null | STRING, INTEGER, FLOAT, … |
| `channel` | string | "MINE" or the channel id the report is for |
| `nextCursor` | string \| null |  |

When the thing you asked about does not exist (or a search matches nothing) the call still succeeds: `output.found` is `false`, `output.data` is `null` and `output.reason` says why (`not_found`, `private`, `no_results`, …). Misses are free unless the notes below say misses are billed.

Pagination: pass the previous response’s `nextCursor` as `cursor` to get the next page; `nextCursor: null` means there are no more results.

## Example request

```bash
curl -sS -X POST "https://api.primaryapi.com/v1/run/youtube.analytics_report" \
  -H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"startDate":"2026-11-01","endDate":"2026-11-14","metrics":["views","estimatedMinutesWatched","subscribersGained"],"dimensions":["day"],"sort":[{"field":"day"}],"limit":2}'
```

## Example response

_Values are placeholders that follow the output schema; `credits` is what this call would cost at the usual price._

```json
{
  "output": {
    "found": true,
    "data": {
      "rows": [
        {
          "day": "2026-11-01",
          "views": 1240,
          "estimatedMinutesWatched": 3915,
          "subscribersGained": 18
        },
        {
          "day": "2026-11-02",
          "views": 1388,
          "estimatedMinutesWatched": 4410,
          "subscribersGained": 22
        }
      ],
      "columnHeaders": [
        {
          "name": "day",
          "columnType": "DIMENSION",
          "dataType": "STRING"
        },
        {
          "name": "views",
          "columnType": "METRIC",
          "dataType": "INTEGER"
        },
        {
          "name": "estimatedMinutesWatched",
          "columnType": "METRIC",
          "dataType": "INTEGER"
        },
        {
          "name": "subscribersGained",
          "columnType": "METRIC",
          "dataType": "INTEGER"
        }
      ],
      "channel": "MINE",
      "nextCursor": "eyJzIjozfQ"
    }
  },
  "provider": "PrimaryAPI",
  "credits": 1,
  "items": 2,
  "requestId": "req_01JBXK6Y2N9V8T4R3Q2P1M0A7Z",
  "nextCursor": null
}
```

## Pricing and reliability

- Usual price: 1 credit per call
- Price ceiling: the usual price, even when a call is retried. A quote’s `maxCredits` is the most a given call can cost; the `maxCredits` routing control caps it per call
- Live 30-day status, success rate, uptime and latency: `GET https://api.primaryapi.com/v1/status/apis?sku=youtube.analytics_report`

## Errors to handle

`invalid_input`, `unauthorized`, `insufficient_balance`, `key_limit_reached`, `trial_cap_reached`, `forbidden`, `not_found`, `idempotency_conflict`, `rate_limited`, `all_sources_failed`, `service_unavailable`, `timeout`. See https://primaryapi.com/docs/errors.

## Notes

Runs as your connected Google account and needs the Read YouTube Analytics capability (youtube_analytics_read). Reports cover your own channel (default) or another channel you own (channelId). Metric and dimension names are YouTube Analytics names; not every combination is a supported report, and YouTube answers an unsupported one as invalid input. Top-video, city and detail reports need a sort and a small limit (200, 250 or 25 rows). The most recent days may not have data yet. Revenue and ad metrics need youtube.revenue_report.

