# Retrieving name of current user in JavaScript (Notebook, Dashboard)

**URL:** <https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236>\
**Category:** Developer Q&A Forum\
**Tags:** coding-assistance\
**Created:** [October 23, 2023, 12:31pm UTC](https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236 "2023-10-23T12:31:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreas\_grabner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/andreas_grabner/32/27879_2.png) [@andreas\_grabner](https://community.dynatrace.com/u/andreas_grabner)\
**Post date:** [October 23, 2023, 12:31pm UTC](https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236/1 "2023-10-23T12:31:56Z")

</div>

Hi

I am trying to get the username of the user that executes some JavaScript in either a notebook or dashboard. I assume that functionality exists in one of the SDKs but I couldnt find anything

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![stefan\_eggersto](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/stefan_eggersto/32/34114_2.png) [@stefan\_eggersto](https://community.dynatrace.com/u/stefan_eggersto)\
**Post date:** [October 24, 2023, 6:09am UTC](https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236/2 "2023-10-24T06:09:18Z")

</div>

Hi [@andreas\_grabner](https://community.dynatrace.com/user/146),

There is currently no SDK available to get the user info, but you can directly call a platform API with the following snippet:

```auto
export default async function() {
  const response = await fetch("/platform/metadata/v1/user");
  const json = await response.json();
  return json.userName;
}

```

An SDK should be available in the near future.

---

<div class="post-metadata">

**Author:** ![andreas\_grabner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/andreas_grabner/32/27879_2.png) [@andreas\_grabner](https://community.dynatrace.com/u/andreas_grabner)\
**Post date:** [October 24, 2023, 8:21am UTC](https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236/3 "2023-10-24T08:21:22Z")

</div>

Thanks!!

FYI - the returned user object has three properties in case anyone is interested: userName, userId, emailAddress

---

<div class="post-metadata">

**Author:** ![gilgi](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gilgi/32/11747_2.png) [@gilgi](https://community.dynatrace.com/u/gilgi)\
**Post date:** [October 24, 2023, 11:18am UTC](https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236/4 "2023-10-24T11:18:27Z")

</div>

[@stefan\_eggersto](https://community.dynatrace.com/user/9516)&nbsp;I would guess it is but to make sure - would the same also apply to indetify the current user running an application?

and&nbsp;[@andreas\_grabner](https://community.dynatrace.com/user/146)&nbsp;thanks for asking this just a few hours before I stumbled upon this issue 🙂

---

<div class="post-metadata">

**Author:** ![stefan\_eggersto](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/stefan_eggersto/32/34114_2.png) [@stefan\_eggersto](https://community.dynatrace.com/u/stefan_eggersto)\
**Post date:** [October 24, 2023, 11:21am UTC](https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236/5 "2023-10-24T11:21:40Z")

</div>

Yes, you can use the same call to identify the app user.

---

<div class="post-metadata">

**Author:** ![MaximilianoML](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/maximilianoml/32/25038_2.png) [@MaximilianoML](https://community.dynatrace.com/u/MaximilianoML)\
**Post date:** [April 10, 2024, 8:38am UTC](https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236/6 "2024-04-10T08:38:10Z")

</div>

Hello,&nbsp;[@stefan\_eggersto](https://community.dynatrace.com/user/9516)&nbsp;!

I’m developing a custom APP, and when I call the API via App Function, I get Error: Authentication required. How can I implicitly authenticate?

Here’s my snippet;

```javascript
export default async function() {
  return fetch("https://{environmentid}.apps.dynatrace.com/platform/metadata/v1/user")
  .then((response) => response.json())
  .then((data)=> {return data})
  .catch((error) => console.log(error));
}

```

---

<div class="post-metadata">

**Author:** ![sinisa\_zubic](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/sinisa_zubic/32/32498_2.png) [@sinisa\_zubic](https://community.dynatrace.com/u/sinisa_zubic)\
**Post date:** [April 15, 2024, 8:44am UTC](https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236/7 "2024-04-15T08:44:46Z")

</div>

Hi&nbsp;[@MaximilianoML](https://community.dynatrace.com/user/73851)

This is expected when you use an absolute URL. If you would use a relative URL, you should be fine

```markup
fetch("/platform/metadata/v1/user");

```

Best,  
Sini

---

<div class="post-metadata">

**Author:** ![muzztafa](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@muzztafa](https://community.dynatrace.com/u/muzztafa)\
**Post date:** [August 1, 2024, 12:51pm UTC](https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236/8 "2024-08-01T12:51:26Z")

</div>

Hi&nbsp;[@sinisa\_zubic](https://community.dynatrace.com/user/38283)&nbsp;,

This works fine as long as the application is running locally. I get a 401 once I deploy it to the platform.  
**Response** :  
{\“error\”:{\“code\”:401,\“message\”:\“Unsupported authorization scheme ‘Api-Token’. Dynatrace platform APIs require the authorization scheme ‘Bearer’.\”,\“details\”:{\“traceId\”:\“3c2803d28b272248ba1b9916ab137948\”}}}"

**my request:**

const url = “/platform/metadata/v1/user”;

const res = await fetch(url, {

headers: {

Authorization: `Api-Token ${tokenCredentials[“token”]}`,

},

});

Any SDK available for this?

---

<div class="post-metadata">

**Author:** ![haris](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/haris/32/38293_2.png) [@haris](https://community.dynatrace.com/u/haris)\
**Post date:** [November 21, 2024, 3:46pm UTC](https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236/9 "2024-11-21T15:46:33Z")

</div>

Hi muzztafa,

the SDK was released in late August. See:&nbsp;[App environment | Dynatrace Developer](https://developer.dynatrace.com/develop/sdks/app-environment/)

You can also check this thread out:&nbsp;[https://community.dynatrace.com/t5/Developer-Q-A-Forum/Dynatrace-App-Current-user-information/m-p/218433](https://community.dynatrace.com/post/218433)

---

<div class="post-metadata">

**Author:** ![s\_wasserbauer](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/s_wasserbauer/32/3811_2.png) [@s\_wasserbauer](https://community.dynatrace.com/u/s_wasserbauer)\
**Post date:** [November 25, 2024, 1:08pm UTC](https://community.dynatrace.com/t/retrieving-name-of-current-user-in-javascript-notebook-dashboard/42236/10 "2024-11-25T13:08:39Z")

</div>

Hey, I’m happy to announce that there is now an SDK package out for a while:&nbsp;[App environment | Dynatrace Developer](https://developer.dynatrace.com/develop/sdks/app-environment/)  
So, you can get the currently logged-in user with:

```javascript
import {getCurrentUserDetails} from "@dynatrace-sdk/app-environment";
export default async function () {
  return getCurrentUserDetails();
}

```

Hope this helps!
