DEV Community

Natasha
Natasha

Posted on

dev.to has no API for replies: the browser path that works

The forem API on dev.to gives you POST /api/articles to publish and POST /api/reactions to like, but there is no route to post a comment or a reply. If you wire up anything that needs to answer a comment, you find that out the hard way: the call returns a 404 HTML page, not a clean JSON error, even with the right Accept: application/vnd.forem.api-v1+json header and the {"comment": {...}} body the docs seem to imply.

I needed exactly that: reply to a comment on my own article from a script. Here is the path that actually posts a reply, by driving the page in a logged-in browser.

Why the API cannot do it

/api/comments is read-only. GET /api/comments?a_id=<article_id> returns the comments, but no write verb is exposed. The site posts comments through its own authenticated web client, not a documented public endpoint. Anything that advertises a comment POST route is guessing.

The working path

Drive the real page in a headless browser that is already signed in, then:

  1. Open the article URL.
  2. Click the reply toggle on the target comment: .comment button.toggle-reply-form.
  3. Set the textarea. A plain el.value = "..." does nothing, because the form is React and the change event never fires. Use the native setter and dispatch the input event:
const ta = document.querySelector('.comment textarea');
const setter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value').set;
setter.call(ta, 'your reply');
ta.dispatchEvent(new Event('input', { bubbles: true }));
Enter fullscreen mode Exit fullscreen mode
  1. Click the form's submit: form.querySelector('button[type=submit]').

Read the reply back

The reply appears as a child of the parent comment. Verify it rather than trusting the click:

GET https://dev.to/api/comments?a_id=<article_id>
Enter fullscreen mode Exit fullscreen mode

Comment bodies come back as body_html, so strip the tags before comparing against what you sent.

What can break

The selectors belong to the web client, not a public contract. .comment button.toggle-reply-form and button[type=submit] are what worked when I wrote this; if dev.to ships a redesign they move. Keep the read-back step so a silent failure looks like a failure instead of a success.

Short version

If you only need to publish, use the API. If you need to reply, the API will not, so sign in a browser, click the toggle, set the textarea with the native setter plus a dispatched input event, submit, and read the comment list back to confirm it landed.

Top comments (0)