Docs menu

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_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).

curl
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"
Python
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"])
TypeScript
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);
}
n8n
{
  "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.

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:

{
  "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"
}