YouTube search API
  1. Docs
  2. YouTube
  3. YouTube search API

YouTube search API

Videos, channels, playlists, Shorts and live streams for a query.

GET /v1/youtube/search

GET /v1/youtube/search

Videos, channels, playlists, Shorts and live streams for a query. Shorts and live results are Posts of type short and live. For stricter title matching use YouTube's intitle: operator.

  • Cost: 1 credit
  • Cache: Results are kept up to 30 days; send max_age_days to reuse them for free.
  • Timeout: A request still running after about 25 seconds answers 202 with a job to poll (Batch and jobs).

Parameters#

NameTypeRequiredDescription
querystringyesSearch terms. Also accepted as keyword, q.
typestringnoKind of result. One of video, channel, playlist, short, live. Also accepted as filter. Also accepted values: videos for video, shorts for short, channels for channel, playlists for playlist.
upload_datestringnoUpload date filter. One of hour, today, week, month, year. Also accepted as uploadDate. Also accepted values: this_week for week, this_month for month, this_year for year.
durationstringnoVideo length (videos only, not Shorts). One of short, medium, long. Also accepted values: under_3_min for short, between_3_and_20_min for medium, over_20_min for long.
sortstringnoOrder of results. YouTube now answers latest and rating in relevance order, so they are refused with invalid_params; use relevance or popular (view count) and narrow with upload_date. One of relevance, latest, popular, rating. Default relevance. Also accepted as sort_by, sortBy, order.
include_extrasbooleannoAlso fetch likes, comment count and description per video (slightly slower). Default false. Also accepted as includeExtras.

Every request also accepts:

  • cursor: the cursor from the previous page (Pagination).
  • region: two-letter country code for results that vary by country. Changing it restarts the cursor chain.
  • trim: true for a smaller response without null fields and extra.
  • raw: true to also get the platform's original object as raw.
  • max_age_days: accept a cached result up to this many days old, for 0 credits (Caching).

Example request#

Set your key in the environment first (see Authentication).

1curl -G "https://api.socialscrape.dev/v1/youtube/search" \2  -H "x-api-key: $SOCIALSCRAPE_API_KEY" \3  --data-urlencode "query=lofi hip hop" \4  --data-urlencode "type=playlist"

Example response#

This is a sample from a recorded response, lists and long text are shortened. Status 200.

200 OKSample response
1{2  "ok": true,3  "credits_charged": 1,4  "credits_remaining": 4999,5  "cached": false,6  "cached_at": null,7  "request_id": "req_3838b9f141b89fb3defc3c92",8  "data": {9    "object": "list",10    "items": [11      {12        "object": "collection",13        "platform": "youtube",14        "id": "PLF3eNE6vR-4WsBf8qnJLqBywqX39QczxJ",15        "url": "https://www.youtube.com/playlist?list=PLF3eNE6vR-4WsBf8qnJLqBywqX39QczxJ",16        "kind": "playlist",17        "title": "1 Hour of Lofi Hip Hop",18        "description": null,19        "owner": {20          "id": null,21          "handle": null,22          "name": "the bootleg boy 2",23          "url": null,24          "avatar_url": null,25          "verified": null26        },27        "item_count": 75,28        "cover_url": "https://i.ytimg.com/vi/1TVlO05Ugjw/hq720.jpg?sqp=-oaymwEXCNAFEJQDSFryq4qpAwkIARUAAIhCGAE=&rs=AOn4CLD21TbNM4alSYIuPb7svRS8e_47Ug",29        "updated_at": null,30        "extra": null31      },32      {33        "object": "collection",34        "platform": "youtube",35        "id": "PLeY3OWvWpq2NZ1yVqYevCYIN5AQwsWXtj",36        "url": "https://www.youtube.com/playlist?list=PLeY3OWvWpq2NZ1yVqYevCYIN5AQwsWXtj",37        "kind": "playlist",38        "title": "The-Simpsons-Chill-Music",39        "description": null,40        "owner": {41          "id": null,42          "handle": null,43          "name": "B1G T3A",44          "url": null,45          "avatar_url": null,46          "verified": null47        },48        "item_count": 30,49        "cover_url": "https://i.ytimg.com/vi/iicfmXFALM8/hq720.jpg?sqp=-oaymwEXCNAFEJQDSFryq4qpAwkIARUAAIhCGAE=&rs=AOn4CLDmeuvnlUc6oCTTZIH_Rouwm-HK7g",50        "updated_at": null,51        "extra": null52      }53    ],54    "cursor": "o20",55    "has_more": true,56    "parent": null57  },58  "cursor": "o20",59  "has_more": true60}

Response#

A list of Post or Profile or Collection or Community objects in data.items, with data.cursor and data.has_more.

See Data models for every field. The envelope around data is described in Responses.

Errors#

Failures are free: credits_charged is 0. Branch on error.code, never on the message.

CodeHTTPRetryMeaning
invalid_params400noA parameter is missing, unknown or has the wrong type.
not_found404noThe platform says this profile, post or item does not exist.

Every request can also fail with the account and platform errors listed on the Errors page.

Example error:

1{2  "ok": false,3  "error": {4    "code": "invalid_params",5    "message": "A parameter is missing, unknown or has the wrong type.",6    "retryable": false7  },8  "credits_charged": 0,9  "request_id": "req_4a2a4bda84085b7dfd559740"10}