# How to find the post id inside a topic

**URL:** https://meta.discourse.org/t/how-to-find-the-post-id-inside-a-topic/189132
**Category:** Development
**Created:** [May 4, 2021, 12:06pm UTC](https://meta.discourse.org/t/how-to-find-the-post-id-inside-a-topic/189132 "2021-05-04T12:06:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Nareshh\_Raja](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nareshh_raja/32/209929_2.png) [@Nareshh\_Raja](https://meta.discourse.org/u/Nareshh_Raja)
#### Post date: [May 4, 2021, 12:06pm UTC](https://meta.discourse.org/t/how-to-find-the-post-id-inside-a-topic/189132/1 "2021-05-04T12:06:23Z")

</div>

We are planning to add permalinks to our old forum links inside discourse.  
We know how to get the category Id and the Topic Id.  
But how can we write a permalink for the post using the Post Id.  
Where can we find the post id?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 4, 2021, 1:57pm UTC](https://meta.discourse.org/t/how-to-find-the-post-id-inside-a-topic/189132/2 "2021-05-04T13:57:56Z")

</div>

If you used an import script there is a post custom field for each post that contains the import id. You can use that and permalink normalization (in site settings) to create the permalinks. You can look in some of the existing importers for “Permalink” to see some examples.

But I’m fairly certain that the post id is in the json load for the topic.

---

<div class="post-metadata">

### Author: ![Nareshh\_Raja](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nareshh_raja/32/209929_2.png) [@Nareshh\_Raja](https://meta.discourse.org/u/Nareshh_Raja)
#### Post date: [May 5, 2021, 2:40pm UTC](https://meta.discourse.org/t/how-to-find-the-post-id-inside-a-topic/189132/3 "2021-05-05T14:40:36Z")

</div>

Thanks Jay.

We are able to get the post id using the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) queries.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 5, 2021, 3:57pm UTC](https://meta.discourse.org/t/how-to-find-the-post-id-inside-a-topic/189132/4 "2021-05-05T15:57:32Z")

</div>

Whatever works, but see for example `https://meta.discourse.org/t/how-to-find-the-post-id-inside-a-topic/189132/3.json`.

But I’d also have a look at

```plaintext
./launcher enter app
rails c
pcfs=PostCustomField.where(name: 'import_id')

```

You can then do something like

```plaintext
pcfs.each do |pcf|
  Permalink.create(...)

```
