> Documentation index: https://docs.scrapier.io/llms.txt
> Auth: header `X-API-Key: <key>` · Base: https://api.scrapier.io/api/v2 · Synchronous; paginate with `cursor` ← `data.next_cursor`.

# YouTube Trending

Structured YouTube data: send `country_code`. Cursor-paginated, 1 credit per successful call.

`GET|POST https://api.scrapier.io/api/v2/youtube-trending/` · 1 credit per successful call · Cursor-paginated

## Overview

Call `GET /api/v2/youtube-trending/` with `country_code`. The results are in `data.videos`; send `data.next_cursor` back as `cursor` to get the next page. 2 optional parameters refine the call (see Parameters).

## Request

```bash
curl -G "https://api.scrapier.io/api/v2/youtube-trending/" \
  -H "X-API-Key: YOUR_API_KEY" \
  --data-urlencode "country_code=US" \
  --max-time 210
```

```python
import requests

resp = requests.get(
    "https://api.scrapier.io/api/v2/youtube-trending/",
    headers={"X-API-Key": "YOUR_API_KEY"},
    params={"country_code": "US"},
    timeout=210,
)
body = resp.json()
if not resp.ok:
    raise RuntimeError(body.get("error") or body.get("detail"))

print(body["data"]["videos"])
```

POST with a JSON body works too (same parameters; the body is merged over the query string).

## Parameters

| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| `X-API-Key` (header) | string | yes | — | Your API key. |
| `country_code` | string | yes | e.g. `US` | Two-letter ISO country code (e.g., US, BD, IN, GB). Required on first call; ignored when `cursor` is supplied. |
| `cursor` | string | no | — | Pagination cursor returned in the previous response's `next_cursor`. Pass it back unchanged to fetch the next page. When `next_cursor` is null, you have reached the last page. |
| `content_type` | string | no | `music` | Trending list: music (trending music videos, 30; regions without that chart fall back to daily top music videos) \| movies (trending trailers, 30) \| top_music_videos (100) \| gaming \| sports \| news \| live \| learning \| fashion. Invalid value -> 400. Locked into the cursor. |
| `use_proxy` | boolean | no | `true` | Route the request through Scrapier's residential proxy pool. Default: `true`. Leave as is unless support tells you otherwise. |
| `raw_data` | boolean | no | `false` | When true, the response carries the full raw upstream payload(s) the scraper received (GraphQL / JSON API bodies, HTML, embedded JSON-LD -- exactly as the platform returned them) under `raw_responses`, in place of the formatted items. When false (default) you get the formatted output. Pagination (`cursor` / `next_cursor`) works the same in both modes. |

## Response

HTTP 200. Results are in `data.videos`. Sample from the live catalog, arrays trimmed to 3 items.

```json
{
  "success": true,
  "data": {
    "country_code": "US",
    "content_type": "music",
    "page": 1,
    "page_size": 25,
    "videos": [
      {
        "type": "video",
        "id": "V-uIp-WuD60",
        "video_id": "V-uIp-WuD60",
        "title": "Patient Zero",
        "status": "OK",
        "url": "https://www.youtube.com/watch?v=V-uIp-WuD60",
        "description": "Provided to YouTube by Universal Music Group\n\nPatient Zero · Taylor Swift\n\nThe Life of a Showgirl: The Encore\n\n℗ 2026 Taylor Swift\n\nReleased on: 2026-09-25\n\nCom",
        "duration": 226,
        "views": "6722880",
        "view_count": 6722880,
        "likes": "95077",
        "like_count": 95077,
        "comments": null,
        "channel": {
          "id": "UCPC0L1d253x-KuMNwa05TpA",
          "name": "Taylor Swift - Topic",
          "handle": null,
          "url": "https://www.youtube.com/channel/UCPC0L1d253x-KuMNwa05TpA",
          "subscriber_count": null,
          "thumbnails": [],
          "badges": []
        },
        "channel_id": "UCPC0L1d253x-KuMNwa05TpA",
        "channel_name": "Taylor Swift - Topic",
        "keywords": [
          "Taylor Swift",
          "テイラースウィフト",
          "テイラー・スウィフト"
        ],
        "is_ratings_allowed": true,
        "is_live": false,
        "is_live_content": false,
        "is_family_safe": true,
        "category": "Music",
        "is_private": false,
        "is_exclusive": false,
        "thumbnails": [
          {
            "url": "https://i.ytimg.com/vi/V-uIp-WuD60/maxresdefault.jpg",
            "width": 1920,
            "height": 1080
          }
        ],
        "embed_url": "https://www.youtube.com/embed/V-uIp-WuD60",
        "is_embeddable": true,
        "is_unlisted": false,
        "publish_date": "2026-09-24T21:02:10-07:00",
        "published_at": "2026-09-24T21:02:10-07:00",
        "relative_date": null,
        "upload_date": "2026-09-24T21:02:10-07:00",
        "trending_position": 1,
        "previous_position": null,
        "periods_on_chart": null,
        "chart_view_count": null,
        "artists": [
          "Taylor Swift"
        ],
        "release_date": "2026-09-24",
        "country_code": "US",
        "content_type": "music",
        "source": "youtube_charts",
        "chart_type": "TRENDING_VIDEOS",
        "enriched": true,
        "scraped_at": "2026-10-03T04:28:40.122Z"
      }
    ],
    "next_cursor": "eyJjdCI6Im11c2ljIiwiaSI6IlVTIiwicCI6Miwic24iOlsiMGExYjJjIl19"
  }
}
```

## Response fields

| Field | Type | Example | Description |
|---|---|---|---|
| `country_code` | string | `US` |  |
| `content_type` | string | `music` |  |
| `page` | integer | `1` |  |
| `page_size` | integer | `25` |  |
| `videos` | array | `[1 item]` | The results. |
| `next_cursor` | string | `eyJjdCI6Im11c2ljIiwiaSI6IlVTIiwicCI6Miwic24iO…` | Pass back as `cursor` for the next page. `null` on the last page. |
| `videos[].type` | string | `video` |  |
| `videos[].id` | string | `V-uIp-WuD60` |  |
| `videos[].video_id` | string | `V-uIp-WuD60` |  |
| `videos[].title` | string | `Patient Zero` |  |
| `videos[].status` | string | `OK` |  |
| `videos[].url` | string | `https://www.youtube.com/watch?v=V-uIp-WuD60` |  |
| `videos[].description` | string | `Provided to YouTube by Universal Music Group …` |  |
| `videos[].duration` | integer | `226` |  |
| `videos[].views` | string | `6722880` |  |
| `videos[].view_count` | integer | `6722880` |  |
| `videos[].likes` | string | `95077` |  |
| `videos[].like_count` | integer | `95077` |  |
| `videos[].comments` | null | `null` |  |
| `videos[].channel` | object | `{…}` |  |
| `videos[].channel_id` | string | `UCPC0L1d253x-KuMNwa05TpA` |  |
| `videos[].channel_name` | string | `Taylor Swift - Topic` |  |
| `videos[].keywords` | array | `[5 items]` |  |
| `videos[].is_ratings_allowed` | boolean | `true` |  |
| `videos[].is_live` | boolean | `false` |  |
| `videos[].is_live_content` | boolean | `false` |  |
| `videos[].is_family_safe` | boolean | `true` |  |
| `videos[].category` | string | `Music` |  |
| `videos[].is_private` | boolean | `false` |  |
| `videos[].is_exclusive` | boolean | `false` |  |
| `videos[].thumbnails` | array | `[1 item]` |  |
| `videos[].embed_url` | string | `https://www.youtube.com/embed/V-uIp-WuD60` |  |
| `videos[].is_embeddable` | boolean | `true` |  |
| `videos[].is_unlisted` | boolean | `false` |  |
| `videos[].publish_date` | string | `2026-09-24T21:02:10-07:00` |  |
| `videos[].published_at` | string | `2026-09-24T21:02:10-07:00` |  |
| `videos[].relative_date` | null | `null` |  |
| `videos[].upload_date` | string | `2026-09-24T21:02:10-07:00` |  |
| `videos[].trending_position` | integer | `1` |  |
| `videos[].previous_position` | null | `null` |  |
| `videos[].periods_on_chart` | null | `null` |  |
| `videos[].chart_view_count` | null | `null` |  |
| `videos[].artists` | array | `[1 item]` |  |
| `videos[].release_date` | string | `2026-09-24` |  |
| `videos[].country_code` | string | `US` |  |
| `videos[].content_type` | string | `music` |  |
| `videos[].source` | string | `youtube_charts` |  |
| `videos[].chart_type` | string | `TRENDING_VIDEOS` |  |
| `videos[].enriched` | boolean | `true` |  |
| `videos[].scraped_at` | string | `2026-10-03T04:28:40.122Z` |  |

## Pagination

Pass `data.next_cursor` back as `cursor` until it is `null`. Required inputs are ignored once a cursor is sent. Each page is one billed call.

```python
import requests

URL = "https://api.scrapier.io/api/v2/youtube-trending/"
HEADERS = {"X-API-Key": "YOUR_API_KEY"}
params = {"country_code": "US"}
items = []

for _ in range(10):  # each page is one billed call
    resp = requests.get(URL, headers=HEADERS, params=params, timeout=210)
    resp.raise_for_status()
    data = resp.json()["data"]
    items.extend(data.get("videos") or [])
    if not data.get("next_cursor"):  # None = last page
        break
    params = {"cursor": data["next_cursor"]}
```

## Errors

Failed calls are free. Branch on HTTP status; the message is in `error` (or `detail`). See https://docs.scrapier.io/errors.md

- **400** Bad input. The exact message varies by endpoint. `{"success":false,"error":"…"}`
- **402** Balance below the endpoint's price. `{"error":"Insufficient credits. Buy more to scrape more.","balance":1,"required":2}`
- **403** Invalid or unknown API key. `{"detail":"Authentication service unavailable or invalid API key."}`
- **429** Throttled — wait for Retry-After. `{"detail":"Request was throttled. Expected available in N seconds."}`
- **404** unknown slug · **503** busy (retry after `Retry-After`) · **5xx** upstream failure or timeout (retry with backoff).

## Notes

- Nothing special: send the inputs, read the result.

## Related

- [YouTube Channel Info](https://docs.scrapier.io/api-reference/youtube/youtube-channel-info.md): Structured YouTube data: send `urls`. Single lookup, 1 credit per successful call.
- [YouTube Channel Live/Streams](https://docs.scrapier.io/api-reference/youtube/youtube-channel-live.md): Structured YouTube data: send `channels`. Cursor-paginated, 1 credit per successful call.
- [YouTube Channel Video Scraper](https://docs.scrapier.io/api-reference/youtube/youtube-channel-video-scraper.md): Structured YouTube data: send `youtube_channels`. Cursor-paginated, 1 credit per successful call.
- [YouTube Comment Replies](https://docs.scrapier.io/api-reference/youtube/youtube-comment-replies.md): Structured YouTube data: send `continuation_tokens`. Cursor-paginated, 1 credit per successful call.
