Reddit

Reddit search API: search posts with HTTP and TypeScript

Run global and subreddit searches, read the response, and paginate within a credit budget using Social Fetch.

Social FetchUpdated

Find public posts about a product, then narrow the search to a community. This walkthrough searches for switching from notion, reads the results in the Playground, and repeats the request from code. It uses Social Fetch's API, with its own key and credit balance.

You'll need a Social Fetch account and credits. Open API keys, enter a name for your script, click Create key, and copy the key from Save your API key before clicking Done. Keep it in your environment as SOCIALFETCH_API_KEY; don't put it in browser code or a public repository. See Quickstart for the full setup.

Choose a search endpoint

EndpointWhat it searchesSDK method
GET /v1/reddit/searchPublic posts across Reddit, using a required queryclient.reddit.search()
GET /v1/reddit/subreddits/searchPosts inside the required subreddit, with an optional queryclient.reddit.searchSubreddit()

The second endpoint searches posts within a community. To decide which communities to investigate, read the subreddit names in global results. To browse a known community's feed, use List subreddit posts.

  1. Open the Playground.
  2. Select Reddit's Search endpoint, GET /v1/reddit/search.
  3. Enter switching from notion in query.
  4. Set sortBy to relevance and timeframe to week.
  5. Click Send and read Response. Example response is a sample response, not the result of your request.
A real Reddit Search response in the Playground, with relevance and week selected and data.posts boxed. The author's username is blurred.
Choose the result order and time range before sending. Your matching posts appear in data.posts.

To send the same request from a terminal, set SOCIALFETCH_API_KEY first. In a Bash shell:

Request
bash

In PowerShell, use $env:SOCIALFETCH_API_KEY and curl.exe when adapting this command. --data-urlencode preserves spaces and punctuation in query values.

Search words can match loosely. Read each title and body before treating it as evidence that someone switched products. A phrase in the query doesn't guarantee an exact phrase match or complete coverage of Reddit.

Read the results and charge

The JSON has two top-level objects: data holds the search results; meta describes this request and its charge.

FieldMeaning
data.postsPosts on this page
data.totalResultsNumber of posts on this page, not all matching posts on Reddit
data.page.hasMoreWhether another page is available
data.page.nextCursorOpaque value to send as cursor on the next request
meta.creditsChargedCredits charged for this request
meta.requestIdRequest identifier to keep for support
The same real global search response scrolled to its pagination and metadata. hasMore and creditsCharged are boxed.
Read hasMore before requesting another page. The metadata records this page's charge.

Global search posts contain id, title, bodyText, subreddit, url, permalink, score, commentCount and createdAt. Many fields can be null: a missing body doesn't mean the search failed, and a null comment count isn't zero. Keep null values when storing results. Use id to deduplicate overlapping searches; use the post's url, when present, to read its comments.

Each completed search page costs 1 credit, including an empty page. Clicking Send again or requesting the next page makes another billable request. Removing duplicate posts afterwards doesn't refund those requests. lookup_failed and 503 temporarily_unavailable responses aren't charged. See Credits and Pricing for credit purchases and plans.

Search inside a subreddit

  1. Select GET /v1/reddit/subreddits/search in the Playground.
  2. Enter ObsidianMD in subreddit and notion in query.
  3. Set sort to relevance and timeframe to week.
  4. Click Send and read Response.
A real Playground search for notion within ObsidianMD. The subreddit input and sort control are boxed; visible private author details are blurred.
The subreddit parameter chooses the community. This endpoint calls its ordering parameter sort.
Request
bash

The response fields differ

Global search uses bodyText, a string subreddit, and commentCount. Subreddit search uses text, an object subreddit with name, and metrics.comments. Its author is an object with username and id, or null. Use the schema for the endpoint you called.

Use the exact subreddit casing from its URL, such as ObsidianMD. Social Fetch's subreddit lookups are case-sensitive. Scoped search defaults to sort=relevance and timeframe=all when omitted. You can omit query to search without keyword text; an empty string is invalid.

Choose filters and sorting

ParameterGlobal searchSubreddit search
queryRequired, 1-512 characters after trimmingOptional, 1-512 characters when provided
CommunityAcross RedditRequired subreddit
OrdersortBy: relevance, new, top, comment-countsort: relevance, hot, top, new, comments
timeframeall, day, week, month, yearall, hour, day, week, month, year
cursorPrevious page's nextCursorPrevious page's nextCursor

Use relevance to explore a topic, new for recent posts, top for score order, or comment-count (comments in scoped search) to find busy discussions. Set filters explicitly when repeating a search. Neither search exposes a page-size limit parameter. The global reference also documents the optional trim flag for requesting a smaller response where available.

Paginate with the SDK

Keep the endpoint, query, sort and timeframe unchanged when passing a cursor. Treat cursors as opaque strings: don't decode, edit or invent them. Stop when hasMore is false, even if the last page has posts. An empty page alone isn't an end condition when hasMore is true.

Install the SDK and a TypeScript runner in your own project:

Request
bash

Save this as reddit-search.mts. The .mts ending allows the top-level await. It reads at most two global search pages (up to 2 credits), deduplicates posts by ID and preserves missing values. It writes request IDs and errors to stderr, with JSON results on stdout.

Request
typescript

Run it with the same environment variable:

Request
bash

If there are more than two pages, this script intentionally returns a partial result. Increase the page budget only after deciding how many credits to spend. A missing or repeated cursor stops the script with an error instead of looping. For a scoped loop, call searchSubreddit() with subreddit and sort, and change the field mapping as described above.

Troubleshooting

SymptomWhat to check
unauthorized (401)Set a valid Social Fetch key in x-api-key. A Reddit OAuth token isn't a Social Fetch key.
insufficient_credits (402)Check the workspace balance. Each additional page needs another credit.
bad_request (400)Use the endpoint's exact parameter names and enum values. Global search requires query; scoped search requires subreddit.
Empty postsCheck the query, community casing and timeframe. Widen one filter, then review the new response. A completed empty search is still charged.
Missing body, counts or thumbnailsThese fields can be null. Scoped thumbnails are usually null. Use the post URL to inspect the discussion.
lookup_failedKeep the error's requestId; try again later or contact support if it persists.
temporarily_unavailable (503)Honour Retry-After when present before retrying. Authenticated searches have no per-minute quota, but capacity failures can still happen.

Raw HTTP errors use error.code, error.message and error.requestId. The SDK returns { ok: false, error }; check ok before reading value. Don't treat an error or a budget-limited run as a complete research result. If needed, contact support with the request ID.

Social Fetch searches public data using its own credentials. Reddit's official Data API is a separate service with its own authentication and access terms. See How to get a Reddit API key if you're deciding between them. These search results are a changing set of available matches, not a complete archive or a measurement of how common an opinion is.

Share this article