Search within a subreddit API
Posts in one subreddit, found through DuckDuckGo's index and in DuckDuckGo's order, each filled in from Reddit with its score and counts.
GET /v1/reddit/subreddit/search
GET /v1/reddit/subreddit/search
Posts in one subreddit, found through DuckDuckGo's index and in DuckDuckGo's order, each filled in from Reddit with its score and counts. Reddit's own search and comment search are not available.
- 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 |
|---|---|---|---|
subreddit | string | yes | Subreddit name without r/. Also accepted as sub. |
query | string | yes | Search terms. Also accepted as keyword, q. |
timeframe | string | no | Only posts from this window. One of day, week, month, year. Also accepted as t, time. |
Every request also accepts:
cursor: the cursor from the previous page (Pagination).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/reddit/subreddit/search" \2 -H "x-api-key: $SOCIALSCRAPE_API_KEY" \3 --data-urlencode "subreddit=python" \4 --data-urlencode "query=asyncio"1import os2import requests34params = {5 "subreddit": "python",6 "query": "asyncio",7}8res = requests.get(9 "https://api.socialscrape.dev/v1/reddit/subreddit/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/reddit/subreddit/search");2url.search = new URLSearchParams({3 "subreddit": "python",4 "query": "asyncio"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 Search within a subreddit",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/reddit/subreddit/search",14 "sendQuery": true,15 "queryParameters": {16 "parameters": [17 {18 "name": "subreddit",19 "value": "python"20 },21 {22 "name": "query",23 "value": "asyncio"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_3e346fd89819874009f60915",8 "data": {9 "object": "list",10 "items": [11 {12 "object": "post",13 "platform": "reddit",14 "id": "146elqk",15 "url": "https://www.reddit.com/r/Python/comments/146elqk/thoughts_on_asyncio/",16 "type": "link",17 "author": {18 "id": "t2_dqm6u",19 "handle": "commandlineluser",20 "name": "commandlineluser",21 "url": "https://www.reddit.com/user/commandlineluser/",22 "avatar_url": "https://www.redditstatic.com/avatars/defaults/v2/avatar_default_6.png",23 "verified": null24 },25 "title": "Thoughts on AsyncIO",26 "text": null,27 "published_at": "2023-06-10T23:36:03.654000Z",28 "duration_seconds": null,29 "language": null,30 "hashtags": null,31 "mentions": null,32 "stats": {33 "views": null,34 "likes": 60,35 "comments": 39,36 "shares": null,37 "saves": null,38 "dislikes": null39 },40 "media": {41 "thumbnail_url": null,42 "video_url": null,43 "audio_url": null,44 "image_urls": null,45 "width": null,46 "height": null47 },48 "song": null,49 "location": null,50 "is_pinned": null,51 "is_sponsored": null,52 "extra": {53 "award_count": 0,54 "domain": "charlesleifer.com",55 "enriched": true,56 "link_url": "https://charlesleifer.com/blog/asyncio/",57 "post_type": "link",58 "score": 60,59 "search_position": 1,60 "source": "duckduckgo",61 "subreddit": "Python",62 "subreddit_id": "t5_2qh0y",63 "upvote_ratio": 0.857142857142857164 }65 },66 {67 "object": "post",68 "platform": "reddit",69 "id": "yqrr94",70 "url": "https://www.reddit.com/r/Python/comments/yqrr94/python_asyncio_the_complete_guide/",71 "type": "link",72 "author": {73 "id": "t2_4j97",74 "handle": "jasonb",75 "name": "jasonb",76 "url": "https://www.reddit.com/user/jasonb/",77 "avatar_url": "https://www.redditstatic.com/avatars/defaults/v2/avatar_default_3.png",78 "verified": null79 },80 "title": "Python Asyncio: The Complete Guide",81 "text": null,82 "published_at": "2022-11-09T18:48:53.197000Z",83 "duration_seconds": null,84 "language": null,85 "hashtags": null,86 "mentions": null,87 "stats": {88 "views": null,89 "likes": 98,90 "comments": 19,91 "shares": null,92 "saves": null,93 "dislikes": null94 },95 "media": {96 "thumbnail_url": null,97 "video_url": null,98 "audio_url": null,99 "image_urls": null,100 "width": null,101 "height": null102 },103 "song": null,104 "location": null,105 "is_pinned": null,106 "is_sponsored": null,107 "extra": {108 "award_count": 0,109 "domain": "superfastpython.com",110 "enriched": true,111 "link_url": "https://superfastpython.com/python-asyncio/",112 "post_type": "link",113 "score": 98,114 "search_position": 2,115 "source": "duckduckgo",116 "subreddit": "Python",117 "subreddit_id": "t5_2qh0y",118 "upvote_ratio": 0.9711538461538461119 }120 }121 ],122 "cursor": "eyJwIjoyLCJmIjp7InEiOiJhc3luY2lvIHNpdGU6cmVkZGl0LmNvbS9yL3B5dGhvbiIsInMiOiIxMCIsIm5leHRQYXJhbXMiOiIiLCJ2IjoibCIsIm8iOiJqc29uIiwiZGMiOiIxMSIsImFwaSI6ImQuanMiLCJ2cWQiOiI0LTI3ODM2ODcwMjU5MDA4NzY1Mzc4MzY2ODQ3MzM5NTMxNzcyOTMzIiwia2wiOiJ3dC13dCJ9...",123 "has_more": true,124 "parent": null125 },126 "cursor": "eyJwIjoyLCJmIjp7InEiOiJhc3luY2lvIHNpdGU6cmVkZGl0LmNvbS9yL3B5dGhvbiIsInMiOiIxMCIsIm5leHRQYXJhbXMiOiIiLCJ2IjoibCIsIm8iOiJqc29uIiwiZGMiOiIxMSIsImFwaSI6ImQuanMiLCJ2cWQiOiI0LTI3ODM2ODcwMjU5MDA4NzY1Mzc4MzY2ODQ3MzM5NTMxNzcyOTMzIiwia2wiOiJ3dC13dCJ9...",127 "has_more": true128}Response#
A list of Post 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.
Related endpoints#
- Subreddit details (
GET /v1/reddit/subreddit/details) - Subreddit posts (
GET /v1/reddit/subreddit/posts) - Reddit post (
GET /v1/reddit/post) - Reddit post comments (
GET /v1/reddit/post/comments) - Reddit post comments (POST body) (
POST /v1/reddit/post/comments) - Reddit video post transcript (
GET /v1/reddit/post/transcript) - Reddit search (
GET /v1/reddit/search)