Reddit research / listening pulse

Search Reddit for product mentions, deduplicate matching threads, and read comments with the TypeScript SDK.

Search Reddit for people discussing a product, narrow the search to communities you know, then read the comments on the busiest matching threads. This example looks for alternatives to Notion and keeps one row per thread, even when several searches find it.

You'll need an API key, credits and the TypeScript SDK. Set SOCIALFETCH_API_KEY in your environment before running the code.

Credit budget

Each completed search page, subreddit lookup and comment page costs 1 credit. Empty completed searches and not_found results still cost a credit. Check meta.creditsCharged for the actual charge.

The example makes three global searches, three subreddit searches and up to three comment requests: up to 9 credits. It reads only the first page of each result. Extra pages cost another credit each. Removing duplicate posts afterwards doesn't refund the searches that found them.

  1. Open the Playground.
  2. Select Reddit's Search endpoint, GET /v1/reddit/search.
  3. Set query to switching from notion, sortBy to relevance and timeframe to week.
  4. Click Send and open Response.
Reddit Search in the Playground with relevance and week selected. A returned post's url is boxed as the input for a comment request. The post author's username is blurred.
Keep each post's url to fetch its comments. This search ranks matches by relevance within the selected week.

Search words can match loosely. Read the returned titles and text before treating a post as a product mention. The code below keeps only posts whose title or body contains notion. That text check still needs human review if the product name is also an ordinary word.

Use sortBy: "new" when you want newest first. The global search returns titles and body text as title and bodyText, with the comment count in commentCount.

Step 2: Search inside a community

Use client.reddit.searchSubreddit() with subreddit and query to search just that community. This method uses sort, where the global search uses sortBy. Its posts have metrics.comments rather than commentCount, and they don't include the body: text is null, so a check on this method's results only matches the title. For bodies from one community, use the global search with the community in the query, such as subreddit:ObsidianMD notion.

Keep the subreddit's exact casing

Social Fetch's subreddit lookups are case-sensitive. Use ObsidianMD, not obsidianmd. Copy the name from the community's URL.

A real Playground subreddit lookup using lowercase obsidianmd returns lookupStatus not_found and meta.creditsCharged of 1. An annotation gives the correct casing, ObsidianMD.
A completed lookup can return not_found and still cost 1 credit. Correct the casing before trying again.

To read a community's latest posts without a keyword, use client.reddit.listSubredditPosts({ subreddit: "ObsidianMD", sort: "new" }).

Step 3: Run the listening pulse

Save this as reddit-pulse.mts. The .mts ending makes it an ES module, so you can use await outside a function. Replace the query phrases and communities with ones relevant to your product. The script searches, deduplicates by post ID, then reads comments on the three threads with the largest returned comment counts. Errors are written separately so one failed request doesn't stop the rest.

import { SocialFetchClient } from "@socialfetch/sdk";

const apiKey = process.env.SOCIALFETCH_API_KEY;
if (!apiKey)
	throw new Error("Set SOCIALFETCH_API_KEY before running the pulse.");

const client = new SocialFetchClient({
	apiKey,
});

// Phrases people use when they look for a way out of Notion.
const QUERIES = [
	"notion alternative",
	"switching from notion",
	"notion too slow",
];
// Communities to search inside, with the casing from each subreddit's URL.
const SUBREDDITS = ["productivity", "ObsidianMD", "selfhosted"];
const BRAND = "notion";

// Search matches words anywhere in a post, so "notion too slow" also finds posts
// about studying slowly. Keep only posts that name the brand.
const namesBrand = (...parts: (string | null)[]) =>
	parts.some((part) => part?.toLowerCase().includes(BRAND));

type Thread = {
	id: string;
	title: string;
	subreddit: string;
	url: string;
	comments: number;
	createdAt: string | null;
	foundBy: string[];
};

async function redditPulse() {
	const threads = new Map<string, Thread>();
	let credits = 0;

	// The same thread often turns up in several searches: keep it once.
	const keep = (thread: Omit<Thread, "foundBy">, search: string) => {
		const seen = threads.get(thread.id);
		if (seen) seen.foundBy.push(search);
		else threads.set(thread.id, { ...thread, foundBy: [search] });
	};

	for (const query of QUERIES) {
		const res = await client.reddit.search({
			query,
			sortBy: "relevance",
			timeframe: "week",
		});
		if (!res.ok) {
			console.error(query, res.error.code, res.error.requestId);
			continue;
		}
		credits += res.value.meta.creditsCharged;
		for (const post of res.value.data.posts) {
			if (!post.url || !namesBrand(post.title, post.bodyText)) continue;
			keep(
				{
					id: post.id,
					title: post.title ?? "",
					subreddit: post.subredditPrefixedName ?? "",
					url: post.url,
					comments: post.commentCount ?? 0,
					createdAt: post.createdAt,
				},
				query,
			);
		}
	}

	for (const subreddit of SUBREDDITS) {
		const res = await client.reddit.searchSubreddit({
			subreddit,
			query: BRAND,
			sort: "relevance",
			timeframe: "week",
		});
		if (!res.ok) {
			console.error(subreddit, res.error.code, res.error.requestId);
			continue;
		}
		credits += res.value.meta.creditsCharged;
		for (const post of res.value.data.posts) {
			if (!namesBrand(post.title, post.text)) continue;
			keep(
				{
					id: post.id,
					title: post.title,
					subreddit: `r/${post.subreddit?.name ?? subreddit}`,
					url: post.url,
					comments: post.metrics.comments ?? 0,
					createdAt: post.createdAt,
				},
				`r/${subreddit}`,
			);
		}
	}

	return { threads: [...threads.values()], credits };
}

async function readComments(thread: Thread) {
	const res = await client.reddit.listPostComments({ url: thread.url });
	if (!res.ok) {
		console.error(thread.url, res.error.code, res.error.requestId);
		return { comments: [], credits: 0 };
	}
	return {
		// Keep the text of top-level comments on the first page, without authors.
		comments: res.value.data.comments.map((c) => ({
			text: c.text,
			score: c.score,
			createdAt: c.createdAt,
		})),
		credits: res.value.meta.creditsCharged,
	};
}

const capturedAt = new Date().toISOString();
const pulse = await redditPulse();

// Read the comments on the three busiest threads.
const busiest = [...pulse.threads]
	.sort((a, b) => b.comments - a.comments)
	.slice(0, 3);
let credits = pulse.credits;
const discussions = [];
for (const thread of busiest) {
	const read = await readComments(thread);
	credits += read.credits;
	discussions.push({ ...thread, topComments: read.comments });
}

console.log(
	JSON.stringify(
		{ capturedAt, credits, threads: pulse.threads, discussions },
		null,
		2,
	),
);

Run it after installing the SDK and tsx in your project:

npx tsx reddit-pulse.mts > reddit-pulse.json

Here is a table built from a real run of that code. It found 12 distinct matching threads and spent 9 credits, including the comment requests. The table shows the busiest 11; the output JSON contains the full list.

A table built from the real SDK response, sorted by comment count. The three largest comment counts are boxed. One thread's foundBy cell records four searches that found the same post, kept once. No usernames are included.
foundBy records the searches that found each thread. A repeated match stays one row.

Step 4: Read comments and check for more pages

The script passes each chosen thread's url to client.reddit.listPostComments(). It keeps the first page's top-level comment text, score and date, without authors. The API also returns nested replies under replies.items; the example leaves those out of its output.

A real Reddit comment response in the Playground. The comment text and page.hasMore false are boxed. The comment author's username is blurred.
Read page.hasMore before requesting another page. A thread's comment count doesn't tell you whether another page is available.

For searches and comments, check data.page.hasMore and pass data.page.nextCursor back as cursor with the same query or post URL. Stop when hasMore is false or your credit budget is reached. Nested reply lists have their own pagination state, so a completed top-level page doesn't mean every reply has been read. See the comments reference for reply cursors.

Keep meta.requestId with any stored response if you need to trace a request. The example totals successful charges and logs error codes and request IDs, so an error can leave you with a partial pulse. Inspect errors before treating the output as complete.

Use the results

Keep capturedAt with each run: rankings and comment counts can change. Read the selected discussions, group the problems people describe, and keep the source URL beside each observation. A busy thread gives you more discussion to read; its comment count doesn't measure how common a problem is across all customers.

If you share the output, omit authors and check comment text for personal details. The example leaves out author fields, but comment text can still identify someone.

For an AI agent, connect MCP. You can start with nl_ask_post and a question such as "Search Reddit for switching from Notion", then use the typed Reddit tools with explicit search options for repeated runs.

On this page