# Which Discourse API can directly get the last comment information of a post?

**URL:** https://meta.discourse.org/t/discourse/381511
**Category:** Development
**Tags:** rest-api
**Created:** [September 4, 2025, 2:22am UTC](https://meta.discourse.org/t/discourse/381511 "2025-09-04T02:22:09Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![McDonald\_Louise](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcdonald_louise/32/520516_2.png) [@McDonald\_Louise](https://meta.discourse.org/u/McDonald_Louise)
#### Post date: [September 4, 2025, 2:22am UTC](https://meta.discourse.org/t/discourse/381511/1 "2025-09-04T02:22:09Z")

</div>

I need a discourse that can directly get the last comment information of a certain post by specifying only the post ID, without specifying the floor, to directly get the last comment information. Is there such an interface?

---

<div class="post-metadata">

### Author: ![MachineScholar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/machinescholar/32/424719_2.png) [@MachineScholar](https://meta.discourse.org/u/MachineScholar)
#### Post date: [September 4, 2025, 2:27am UTC](https://meta.discourse.org/t/discourse/381511/2 "2025-09-04T02:27:09Z")

</div>

I would recommend using a [data explorer](https://meta.discourse.org/t/32566?silent=true) query for that. You can programmatically run queries and get JSON results. Here you go:

```sql
-- [params]
-- post_id :post_id

SELECT
  p.id,
  p.topic_id,
  p.post_number,
  p.raw AS raw_content, -- Markdown/source
  p.cooked AS html_content, -- Rendered HTML
  p.user_id,
  p.created_at,
  p.updated_at
FROM posts p
WHERE p.id = :post_id
  AND p.deleted_at IS NULL -- drop if you want deleted posts too
-- AND p.hidden = false -- optionally exclude hidden posts
LIMIT 1;

```

---

<div class="post-metadata">

### Author: ![McDonald\_Louise](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcdonald_louise/32/520516_2.png) [@McDonald\_Louise](https://meta.discourse.org/u/McDonald_Louise)
#### Post date: [September 4, 2025, 2:43am UTC](https://meta.discourse.org/t/discourse/381511/3 "2025-09-04T02:43:42Z")

</div>

It is two different services, and can only be obtained by interfacing.

---

<div class="post-metadata">

### Author: ![MachineScholar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/machinescholar/32/424719_2.png) [@MachineScholar](https://meta.discourse.org/u/MachineScholar)
#### Post date: [September 4, 2025, 2:45am UTC](https://meta.discourse.org/t/discourse/381511/4 "2025-09-04T02:45:12Z")

</div>

Maybe you could explain a little bit more what you’re trying to achieve? Then I could make you a Python script for example ☺

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [September 4, 2025, 3:00am UTC](https://meta.discourse.org/t/discourse/381511/5 "2025-09-04T03:00:50Z")

</div>

You can create the [data explorer](https://meta.discourse.org/t/32566?silent=true) query, then call it [using the API](https://meta.discourse.org/t/run-data-explorer-queries-with-the-discourse-api/120063?username=natedhaliwal).

---

<div class="post-metadata">

### Author: ![McDonald\_Louise](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcdonald_louise/32/520516_2.png) [@McDonald\_Louise](https://meta.discourse.org/u/McDonald_Louise)
#### Post date: [September 9, 2025, 7:41am UTC](https://meta.discourse.org/t/discourse/381511/6 "2025-09-09T07:41:07Z")

</div>

Thank you all, I have already solved it in other ways.

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [September 9, 2025, 8:00am UTC](https://meta.discourse.org/t/discourse/381511/7 "2025-09-09T08:00:28Z")

</div>

Do you mind sharing how you solved it? It could help others with the same question.

---

<div class="post-metadata">

### Author: ![McDonald\_Louise](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcdonald_louise/32/520516_2.png) [@McDonald\_Louise](https://meta.discourse.org/u/McDonald_Louise)
#### Post date: [November 19, 2025, 3:16am UTC](https://meta.discourse.org/t/discourse/381511/8 "2025-11-19T03:16:33Z")

</div>

It is done through two interface calls, one to get the total number of comments and then use that number to get the last one.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 19, 2025, 3:16am UTC](https://meta.discourse.org/t/discourse/381511/9 "2025-12-19T03:16:50Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
