Search posts on Reddit by keyword (global or within a subreddit), to find threads where your software/solution is relevant (people asking for recommendations, comparing alternatives, describing the problem).
{"sort":"string optional (relevance|new|top|comments)","limit":"int optional (default 25, max 100)","query":"string","subreddit":"string optional"}{"count":"int","query":"string","results":"array of { title, subreddit, author, ups, num_comments, created, permalink, selftext, link, id }","subreddit":"string|null"}Search posts on Reddit by keyword (global or within a subreddit), to find threads where your software/solution is relevant (people asking for recommendations, comparing alternatives, describing the problem). Uses Reddit's .json endpoint (clean, no anti-bot) with session cookies. PARAMS: query (text, e.g. 'best CRM for small business' or 'alternative to notion'); subreddit optional (e.g. 'SaaS' or 'r/startups'; if set, searches ONLY there with restrict_sr); sort optional ('relevance' default | 'new' | 'top' | 'comments'); limit optional (default 25, max 100). Returns { count, query, subreddit, results:[{ title, subreddit, author, ups, num_comments, created, permalink, selftext, link, id }] }. selftext = post body (truncated to 800 chars; the material to personalize the reply). link = external URL if it's a link-post. permalink feeds reddit-get-thread / commenting. Requires an active Reddit session. Stable .json endpoint.
params. It does the in-page work and returns the JSON in returns.( async (root, params) => { const q = String((params && params.query) || '').trim(); const sub = String((params && params.subreddit) || '').trim().replace(/^/?r//,''); const sort = String((params && params.sort) || 'relevance').trim(); let limit = parseInt(String((params && params.limit) || '25'),10) || 25; if(limit>100) limit=100; const base = sub ? ('/r/'+encodeURIComponent(sub)+'/search.json') : '/search.json'; const url = base + '?q='+encodeURIComponent(q) + '&sort='+encodeURIComponent(sort) + '&limit='+limit + '&type=link&raw_json=1' + (sub?'&restrict_sr=1':''); let r, d; try { r = await fetch(url, { credentials:'include', headers:{'accept':'application/json'} }); d = await r.json(); } catch(e){ return { error:'fetch fail: '+String(e), count:0, results:[] }; } const kids = (d.data && d.data.children) || []; const results = kids.filter(k=>k.kind==='t3').map(k=>{ const p=k.data; return { id: p.id, title: p.title, subreddit: p.subreddit, author: p.author, ups: p.ups, num_comments: p.num_comments, created: p.created_utc, permalink: 'https://www.reddit.com'+p.permalink, selftext: (p.selftext||'').slice(0,800) || null, link: p.is_self ? null : (p.url||null) }; }); return { count: results.length, query:q, subreddit: sub||null, results }; } )
Response text contains "reddit".