# Discourse API Get Current Topic

**URL:** <https://meta.discourse.org/t/discourse-api-get-current-topic/174068>\
**Category:** Product Support\
**Created:** [December 23, 2020, 2:50am UTC](https://meta.discourse.org/t/discourse-api-get-current-topic/174068 "2020-12-23T02:50:53Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![littleviolette](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@littleviolette](https://meta.discourse.org/u/littleviolette)\
**Post date:** [December 23, 2020, 2:50am UTC](https://meta.discourse.org/t/discourse-api-get-current-topic/174068/1 "2020-12-23T02:50:53Z")

</div>

HI!

I see that Discourse’s API script plug-in can get the current user:

```
<script type="text/discourse-plugin" version="0.8.18">
    if(api.getCurrentUser() != null) {
        $("#logged-in-user").text(" " + api.getCurrentUser().username);
    }
</script>

```

Is there a similar command to get the current topic? My use case is to change the URL of the [redirect button at the end of a post](https://github.com/techAPJ/discourse-topic-group-button) to a [pre-filled link to PM](https://meta.discourse.org/t/compose-a-new-pre-filled-personal-message-via-url/35984) the original poster. In order the find the username of the original poster, it seems like I would need to get the topic id first, then query the original poster via `"/t/<TOPIC_ID>.json"`?

The button plug-in has `<TOPIC_ID>` built in, but I am not sure how that can be done using javascript under Admin \> Customization. Thank you!

---

_[View the full topic](https://meta.discourse.org/t/discourse-api-get-current-topic/174068)._
