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_daysto reuse them for free. - Timeout: A request still running after about 25 seconds answers
202with a job to poll (Batch and jobs).
Parameters#
| Name | Type | Required | Description |
|---|---|---|---|
query | string | yes | Search terms. Also accepted as keyword, q. |
type | string | no | Kind 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_date | string | no | Upload 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. |
duration | string | no | Video 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. |
sort | string | no | Order 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_extras | boolean | no | Also 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:truefor a smaller response withoutnullfields andextra.raw:trueto also get the platform's original object asraw.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"1import os2import requests34params = {5 "query": "lofi hip hop",6 "type": "playlist",7}8res = requests.get(9 "https://api.socialscrape.dev/v1/youtube/search",10 headers={"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]},11 params=params,12)13body = res.json()1415if body["ok"]:16 print(body["data"])17else:18 print(body["error"]["code"], body["error"]["message"])1const url = new URL("https://api.socialscrape.dev/v1/youtube/search");2url.search = new URLSearchParams({3 "query": "lofi hip hop",4 "type": "playlist"5}).toString();6const res = await fetch(url, {7 headers: { "x-api-key": process.env.SOCIALSCRAPE_API_KEY! },8});9const body = await res.json();1011if (body.ok) {12 console.log(body.data);13} else {14 console.error(body.error.code, body.error.message);15}1{2 "nodes": [3 {4 "name": "SocialScrape YouTube search",5 "type": "n8n-nodes-base.httpRequest",6 "typeVersion": 4.2,7 "position": [8 0,9 010 ],11 "parameters": {12 "method": "GET",13 "url": "https://api.socialscrape.dev/v1/youtube/search",14 "sendQuery": true,15 "queryParameters": {16 "parameters": [17 {18 "name": "query",19 "value": "lofi hip hop"20 },21 {22 "name": "type",23 "value": "playlist"24 }25 ]26 },27 "sendHeaders": true,28 "headerParameters": {29 "parameters": [30 {31 "name": "x-api-key",32 "value": "={{ $env.SOCIALSCRAPE_API_KEY }}"33 }34 ]35 }36 }37 }38 ],39 "connections": {}40}Example response#
This is a sample from a recorded response, lists and long text are shortened. Status 200.
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.
| Code | HTTP | Retry | Meaning |
|---|---|---|---|
invalid_params | 400 | no | A parameter is missing, unknown or has the wrong type. |
not_found | 404 | no | The 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}Related endpoints#
- YouTube channel details (
GET /v1/youtube/channel) - YouTube channel videos (
GET /v1/youtube/channel/videos) - Search inside a YouTube channel (
GET /v1/youtube/channel/search) - YouTube channel playlists (
GET /v1/youtube/channel/playlists) - YouTube channel Shorts (
GET /v1/youtube/channel/shorts) - YouTube channel live streams (
GET /v1/youtube/channel/lives) - YouTube channel community posts (
GET /v1/youtube/channel/community-posts) - YouTube video or Short details (
GET /v1/youtube/video)