YouTube search
Beta 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
- Status: Beta. Built and tested against recorded responses; the shape may still gain fields.
- 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).
curl -G "https://api.socialscrape.io/v1/youtube/search" \
-H "x-api-key: $SOCIALSCRAPE_API_KEY" \
--data-urlencode "query=lofi hip hop" \
--data-urlencode "type=playlist"import os
import requests
params = {
"query": "lofi hip hop",
"type": "playlist",
}
res = requests.get(
"https://api.socialscrape.io/v1/youtube/search",
headers={"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]},
params=params,
)
body = res.json()
if body["ok"]:
print(body["data"])
else:
print(body["error"]["code"], body["error"]["message"])const url = new URL("https://api.socialscrape.io/v1/youtube/search");
url.search = new URLSearchParams({
"query": "lofi hip hop",
"type": "playlist"
}).toString();
const res = await fetch(url, {
headers: { "x-api-key": process.env.SOCIALSCRAPE_API_KEY! },
});
const body = await res.json();
if (body.ok) {
console.log(body.data);
} else {
console.error(body.error.code, body.error.message);
}{
"nodes": [
{
"name": "SocialScrape YouTube search",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
0,
0
],
"parameters": {
"method": "GET",
"url": "https://api.socialscrape.io/v1/youtube/search",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "query",
"value": "lofi hip hop"
},
{
"name": "type",
"value": "playlist"
}
]
},
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "x-api-key",
"value": "={{ $env.SOCIALSCRAPE_API_KEY }}"
}
]
}
}
}
],
"connections": {}
}Example response#
This is a sample from a recorded response, lists and long text are shortened. Status 200.
{
"ok": true,
"credits_charged": 1,
"credits_remaining": 4999,
"cached": false,
"cached_at": null,
"request_id": "req_3838b9f141b89fb3defc3c92",
"data": {
"object": "list",
"items": [
{
"object": "collection",
"platform": "youtube",
"id": "PLF3eNE6vR-4WsBf8qnJLqBywqX39QczxJ",
"url": "https://www.youtube.com/playlist?list=PLF3eNE6vR-4WsBf8qnJLqBywqX39QczxJ",
"kind": "playlist",
"title": "1 Hour of Lofi Hip Hop",
"description": null,
"owner": {
"id": null,
"handle": null,
"name": "the bootleg boy 2",
"url": null,
"avatar_url": null,
"verified": null
},
"item_count": 75,
"cover_url": "https://i.ytimg.com/vi/1TVlO05Ugjw/hq720.jpg?sqp=-oaymwEXCNAFEJQDSFryq4qpAwkIARUAAIhCGAE=&rs=AOn4CLD21TbNM4alSYIuPb7svRS8e_47Ug",
"updated_at": null,
"extra": null
},
{
"object": "collection",
"platform": "youtube",
"id": "PLeY3OWvWpq2NZ1yVqYevCYIN5AQwsWXtj",
"url": "https://www.youtube.com/playlist?list=PLeY3OWvWpq2NZ1yVqYevCYIN5AQwsWXtj",
"kind": "playlist",
"title": "The-Simpsons-Chill-Music",
"description": null,
"owner": {
"id": null,
"handle": null,
"name": "B1G T3A",
"url": null,
"avatar_url": null,
"verified": null
},
"item_count": 30,
"cover_url": "https://i.ytimg.com/vi/iicfmXFALM8/hq720.jpg?sqp=-oaymwEXCNAFEJQDSFryq4qpAwkIARUAAIhCGAE=&rs=AOn4CLDmeuvnlUc6oCTTZIH_Rouwm-HK7g",
"updated_at": null,
"extra": null
}
],
"cursor": "o20",
"has_more": true,
"parent": null
},
"cursor": "o20",
"has_more": true
}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:
{
"ok": false,
"error": {
"code": "invalid_params",
"message": "A parameter is missing, unknown or has the wrong type.",
"retryable": false
},
"credits_charged": 0,
"request_id": "req_4a2a4bda84085b7dfd559740"
}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)