# Get back Username with API Key?

**URL:** https://meta.discourse.org/t/get-back-username-with-api-key/204030
**Category:** Development
**Created:** [September 20, 2021, 4:43pm UTC](https://meta.discourse.org/t/get-back-username-with-api-key/204030 "2021-09-20T16:43:52Z")
**Posts on this page:** 2
**Page:** 1

<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: [September 20, 2021, 4:43pm UTC](https://meta.discourse.org/t/get-back-username-with-api-key/204030/1 "2021-09-20T16:43:52Z")

</div>

Hi There. When using the [per-user api key process](https://meta.discourse.org/t/user-api-keys-specification/48536) to get back a per-user api key from discourse, is it also possible to get back the user’s username at the same time?

---

<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: [September 20, 2021, 7:37pm UTC](https://meta.discourse.org/t/get-back-username-with-api-key/204030/2 "2021-09-20T19:37:05Z")

</div>

I’ve found a workaround: if you have the key, then when you make an authenticated call to the discourse api, it returns as a header “x-discourse-username: username”. Thanks to @RGJ for the tip.

So, for example, you can get back the key from discourse, and then use the key in an api call to an endpoint like /site.json.

Then parse the response headers, like:

```plaintext
....then((response) => {
          var headerResponseArray = (JSON.stringify(response.headers)).split(',')
          headerResponseArray.forEach((h) => {
             if (h.includes('x-discourse-username')) {
                 var userNameRaw = h.split(':')[1].trim()
             }
          })
    })

```

* * *

It would still be faster if I could just get back the username directly when discourse sends back the per-user api key itself. If anyone has a way to do that, please let me know.
