23 Oct 2023 01:31 PM
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.
Solved! Go to Solution.
24 Oct 2023 07:09 AM - edited 12 Dec 2023 10:55 AM
Hi @andreas_grabner,
There is currently no SDK available to get the user info, but you can directly call a platform API with the following snippet:
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.
24 Oct 2023 09:21 AM - edited 24 Oct 2023 09:22 AM
Thanks!!
FYI - the returned user object has three properties in case anyone is interested: userName, userId, emailAddress
24 Oct 2023 12:18 PM
@stefan_eggersto I would guess it is but to make sure - would the same also apply to indetify the current user running an application?
and @andreas_grabner thanks for asking this just a few hours before I stumbled upon this issue 🙂
24 Oct 2023 12:21 PM
Yes, you can use the same call to identify the app user.
10 Apr 2024 09:38 AM
Hello, @stefan_eggersto !
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;
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));
}
15 Apr 2024 09:44 AM
This is expected when you use an absolute URL. If you would use a relative URL, you should be fine
fetch("/platform/metadata/v1/user");
Best,
Sini
01 Aug 2024 01:51 PM
Hi @sinisa_zubic ,
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?
21 Nov 2024 03:46 PM
Hi muzztafa,
the SDK was released in late August. See: https://developer.dynatrace.com/develop/sdks/app-environment/
You can also check this thread out: https://community.dynatrace.com/t5/Developer-Q-A-Forum/Dynatrace-App-Current-user-information/m-p/21...
25 Nov 2024 01:08 PM
Hey, I'm happy to announce that there is now an SDK package out for a while: https://developer.dynatrace.com/develop/sdks/app-environment/
So, you can get the currently logged-in user with:
import {getCurrentUserDetails} from "@dynatrace-sdk/app-environment";
export default async function () {
return getCurrentUserDetails();
}
Hope this helps!