How do I sort Reddit comments by newest and retain reply structure?
To read the newest comments on a Reddit post first, call reddit.app.fetch_post_comments with sort_type:"NEW". A URL containing /comments/abc123/ means post_id:"t3_abc123". When the comment tree has another page, pass the returned more.cursor as after in the next request. Save each tree entry’s parentId to keep the reply structure.
Which sort should I choose?
Use NEW for newest first. sort_type accepts CONFIDENCE (default), NEW, TOP, HOT, CONTROVERSIAL, OLD and RANDOM, and the values are case-sensitive. TOP sorts comments by score; TOP does not limit the results to top-level comments. Set need_format to false to get the raw tree structure this page describes.
Where are the text, score and reply relationships?
First check that the top-level status is succeeded. Then read each entry of data.postInfoById.commentForest.trees[]:
depth=0 marks a top-level comment. trees[] is a flat list of every returned node, so trees[] holds replies as well as top-level comments. A childCount value does not mean the response contains that many replies; count the replies you actually received.
Where does after come from?
Read data.postInfoById.commentForest.pageInfo.hasNextPage:
false: the comment list has no next page.true: takemore.cursorfrom the last entry oftrees[]and pass the cursor asafter. Keeppost_idandsort_typeunchanged.
Pass the cursor exactly as returned. Do not increment the cursor, and do not pass a search endCursor or another reply action’s cursor as after.
When hasNextPage is true but more.cursor is empty, stop and save the request_id; do not replay page one. All four historical samples recorded by the backend have a null more, so your code must handle the empty-cursor case instead of guessing a field. Also stop on a repeated cursor, a business failure or when you reach your page budget. Reaching the page budget ends your batch; the thread can still have more comments.
The CSV exporter export_comments.py from the comment export guide keeps every valid comment the exporter already received and reports one stop reason:
missing_usable_cursor:hasNextPageis true but no usable cursor came back.provider_end: the comment-list pagination ended; unexpanded reply branches can remain.next_page_available: a cursor exists. Requesting the next page is a separate charged call that you decide on.
The exporter always sets all_comments_collected to false. Within one response, two different nodes with the same comment ID stop the export. Changes between separately saved pages stay in the merge step’s observation table.
Does the comment tree contain every reply?
No. The tree contains only the nodes returned in the response; hidden or removed content, later pages and unexpanded branches are not in the tree. Save node.isRemoved and never reconstruct removed text. Count and deduplicate by actual comment ID. When a reply’s parent is not on the same comment page, keep the reply’s parentId for a later merge instead of turning the reply into a top-level comment.
Export comments and relationships · Reddit questions
Sources: the input contract for data:reddit.app.fetch_post_comments, the backend output structure from four samples dated 2026-09-24, and the gateway’s current renderer.
After export, the reviewed question-backlog workflow counts top-level comments and replies separately and checks each supporting excerpt against the original response. A reply whose parent is missing stays a reply; do not count the reply as an independent top-level complaint. A comment count is not the share of customers who have the problem.
Prepare the correct post request from a copied link
Use the ID right after /comments/ as the post ID, not the last path segment: a comment permalink contains the post ID and, later, a comment ID. t3_ marks a post and t1_ marks a comment; replacing a comment ID’s prefix does not produce a post ID. Reddit’s thing-ID documentation describes both prefixes.
Save the script below as reddit_post_request.py. The script accepts a lowercase t3_ fullname, or a standard HTTPS post or comment permalink on reddit.com, www.reddit.com, old.reddit.com or new.reddit.com. The script rejects a bare ID because a bare ID does not say whether the ID names a post or a comment. Open a /s/ sharing link, a shortened link, a community page or an external URL first, and copy the final post URL; the script does not follow redirects and makes no paid calls.
The IDs in the command are examples. For the example link, request.json targets t3_abc123, and input-audit.json records that the input pointed at a comment. The request reads the first comment page of the containing post; the request does not fetch only comment def456 and does not keep a share link’s on-page filter. The request sets NEW order, the raw structure, an empty first-page after and en-US. The en-US language preference does not filter authors or content to English. The script refuses to write into an existing output directory.
Check the current price of reddit.app.fetch_post_comments with Inspect before you send the generated body. When this page was written, Inspect listed the first comment page at $0.003; preparing the JSON is free, and each later page is a separate call. After the cost is approved, send request.json to /v1/social-data/call with your own Bearer key and save the full response. Then follow the CSV export and reviewed backlog. The script checks link syntax only; the API response shows whether the post exists, is public and has retrievable comments.

