Comment on Reddit (reply to a post or a comment) via API.
{"text":"string (comment, markdown)","parentId":"string (post id base36, or fullname t3_/t1_)"}{"errors":"array","posted":"bool","status":"int","parentId":"string","permalink":"url|null"}Comment on Reddit (reply to a post or a comment) via API. Does a POST to /api/comment with the session's modhash (pulled from /api/me.json). PARAMS: parentId (who you're replying to: the post's base36 id -> prefixed with t3_; or a full fullname t3_xxx (post) / t1_xxx (comment). Comes from the id field of reddit-search-posts / reddit-get-thread) and text (the comment, markdown allowed). HEADS UP IRREVERSIBLE: each run PUBLISHES a real comment (can be deleted afterwards). Reddit is VERY sensitive to self-promotion/spam: comment with value, no bare links, or you'll get banned/shadowbanned. NOT VERIFIED (built from the /api/comment + modhash pattern, without posting). Returns { posted, status, parentId, errors, permalink }. The comment is written by Claude (the loop) based on the thread (reddit-get-thread) + your goal. Requires a Reddit session. If Reddit migrates /api/comment to GraphQL, recapture.
params. It does the in-page work and returns the JSON in returns.( async (root, params) => { let parent = String((params && params.parentId) || '').trim(); const text = String((params && params.text) || ''); if(!parent || !text) return { posted:false, error:'missing parentId or text' }; if(!/^t[0-9]/.test(parent)) parent = 't3'+parent; let modhash=''; try { const mr=await fetch('/api/me.json',{credentials:'include',headers:{'accept':'application/json'}}); const md=await mr.json(); modhash=(md.data&&md.data.modhash)||''; } catch(e){ return { posted:false, error:'modhash fail: '+String(e) }; } if(!modhash) return { posted:false, error:'no modhash (session?)' }; const body = 'api_type=json&thing_id='+encodeURIComponent(parent)+'&text='+encodeURIComponent(text)+'&uh='+encodeURIComponent(modhash); let r, d; try { r = await fetch('/api/comment', { method:'POST', credentials:'include', headers:{ 'content-type':'application/x-www-form-urlencoded; charset=UTF-8', 'x-modhash':modhash, 'accept':'application/json' }, body }); d = await r.json().catch(()=>null); } catch(e){ return { posted:false, error:'post fail: '+String(e) }; } const errors = (d && d.json && d.json.errors) ? d.json.errors : []; let newUrl=null; try { newUrl = d.json.data.things[0].data.permalink; } catch(e){} return { posted: (r.ok && errors.length===0), status:r.status, parentId:parent, errors, permalink: newUrl?('https://www.reddit.com'+newUrl):null }; } )
Response text contains "reddit".