Search within a subreddit API
  1. Docs
  2. Reddit
  3. Search within a subreddit API

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_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
subredditstringyesSubreddit name without r/. Also accepted as sub.
querystringyesSearch terms. Also accepted as keyword, q.
timeframestringnoOnly 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: 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/reddit/subreddit/search" \2  -H "x-api-key: $SOCIALSCRAPE_API_KEY" \3  --data-urlencode "subreddit=python" \4  --data-urlencode "query=asyncio"

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

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.