# Getting Post ID with Topic ID - API Help Needed

**URL:** https://meta.discourse.org/t/getting-post-id-with-topic-id-api-help-needed/44239
**Category:** Development
**Created:** [May 14, 2016, 1:20pm UTC](https://meta.discourse.org/t/getting-post-id-with-topic-id-api-help-needed/44239 "2016-05-14T13:20:31Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![P16](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@P16](https://meta.discourse.org/u/P16)
#### Post date: [May 14, 2016, 1:20pm UTC](https://meta.discourse.org/t/getting-post-id-with-topic-id-api-help-needed/44239/1 "2016-05-14T13:20:31Z")

</div>

Hi Everyone,

We are setting up a new Discourse forum and needed some help with the API.

One of the changes we are making is that we show the first post in a topic on the topic page (like Topic Preview). Since most posts will be visual, we show the image, the title, the replies and likes, etc of the topic to the user. Something like this:

 ![](https://global.discourse-cdn.com/meta/original/3X/3/4/34b1c4245201cf670720f0d1f792b0005c47b628.png)

We wanted the user to be able to like the first post in the topic by clicking on the heart icon from the main page. How can we get the first post id of a topic from the main page since we only have the topic id?

Also, once we get the post id, we need to send that and the post action type id as 2 to [http://DiscourseURL/post\_actions](http://DiscourseURL/post_actions)  
Is that correct?

Thanks!

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [May 14, 2016, 2:39pm UTC](https://meta.discourse.org/t/getting-post-id-with-topic-id-api-help-needed/44239/2 "2016-05-14T14:39:15Z")

</div>

Using this topic as an example: You topic ID is `44239`.

A `GET` to `https://meta.discourse.org/t/44239.json` returns an object where `post_stream.posts[0].id = 194190`.

I then liked your post by `POST`ing to `https://meta.discourse.org/post_actions` with `id=194190&post_action_type_id=2&flag_topic=false`. This request needs to be authenticated by an API key or cookies.

---

<div class="post-metadata">

### Author: ![P16](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@P16](https://meta.discourse.org/u/P16)
#### Post date: [May 14, 2016, 2:46pm UTC](https://meta.discourse.org/t/getting-post-id-with-topic-id-api-help-needed/44239/3 "2016-05-14T14:46:30Z")

</div>

Thank you so much Felix. That helps a lot 🙂

---

<div class="post-metadata">

### Author: ![doserved](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@doserved](https://meta.discourse.org/u/doserved)
#### Post date: [October 31, 2016, 10:04pm UTC](https://meta.discourse.org/t/getting-post-id-with-topic-id-api-help-needed/44239/4 "2016-10-31T22:04:14Z")

</div>

A tangential question.

I am using subfolders.

I can type [https://mysite](https://mysite),com/subfolder/t/xx and get to the topic fine.

If I type [https://mysite.com/subfolder/p/yyyy](https://mysite.com/subfolder/p/yyyy) it translates to [https://mysite](https://mysite),com/t/title/xx/yyyy but does not include the subfolder so it doesn’t display.

Thoughts?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [October 31, 2016, 10:38pm UTC](https://meta.discourse.org/t/getting-post-id-with-topic-id-api-help-needed/44239/5 "2016-10-31T22:38:47Z")

</div>

Possibly a bug cc @neil

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [November 1, 2016, 7:21pm UTC](https://meta.discourse.org/t/getting-post-id-with-topic-id-api-help-needed/44239/6 "2016-11-01T19:21:32Z")

</div>

> [@doserved](#):
>
> If I type [https://mysite.com/subfolder/p/yyyy](https://mysite.com/subfolder/p/yyyy) it translates to [https://mysite](https://mysite),com/t/title/xx/yyyy but does not include the subfolder so it doesn’t display.

I [fixed](https://github.com/discourse/discourse/commit/29edbafac7bd84f6dd1d7b95f86c0ad410d8f600) that today.

---

<div class="post-metadata">

### Author: ![doserved](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@doserved](https://meta.discourse.org/u/doserved)
#### Post date: [November 2, 2016, 7:20pm UTC](https://meta.discourse.org/t/getting-post-id-with-topic-id-api-help-needed/44239/7 "2016-11-02T19:20:02Z")

</div>

Thanks! I’ll try it out after the plugins I’m using are fixed to work with the latest version of Discourse.

---

<div class="post-metadata">

### Author: ![JQ331](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@JQ331](https://meta.discourse.org/u/JQ331)
#### Post date: [July 28, 2021, 6:30pm UTC](https://meta.discourse.org/t/getting-post-id-with-topic-id-api-help-needed/44239/8 "2021-07-28T18:30:22Z")

</div>

> [@fefrei](#):
>
> A `GET` to `https://meta.discourse.org/t/44239.json` returns an object where `post_stream.posts[0].id = 194190` .

This is helpful. One thing I wanted to note, don’t forget the term “data” when parsing the response. The form of the response is: `{"data":{"post_stream":{"posts":[{"id":...`

So if you are looking to get the id of the topic post (ie, the first post in the topic), the syntax would be `response.data.post_stream.posts[0].id`
