Retrieving name of current user with API

Hi,

I’m trying to get the current user name and id using the platform API with a platform token.

I’ve checked the Swagger UI for the `Identity and Access Management` but did not find any solution.

Is there an API available for fetching the medata of the owner of the platform token without administrator permissions?

Hi flomaz,

we already have an SDK released earlier this year for this purpose. Please see: App environment | Dynatrace Developer

You can also check this thread with more information: https://community.dynatrace.com/t5/Developer-Q-A-Forum/Dynatrace-App-Current-user-information/m-p/218433

Let me know if you need anything else.

Hi there

You can use the @dynatrace-sdk/app-environment sdk to get the user details as following:

// import the function
import { getCurrentUserDetails } from "@dynatrace-sdk/app-environment";

// get the user details
const userDetails = getCurrentUserDetails();

// do something wit it
console.log(userDetails);

Thanks

Indermohan Singh

Hello @imsingh

Thanks
I would like to fetch it from a Python script, for this reason I cannot use the SDK. :disappointed_face:

Hi flomaz,

can you try using this:

https://{environmentid}.apps.dynatrace.com/platform/metadata/v1/user

This should return json with following info: username, ID and email address like so:

{"userName":"Haris H","userId":"621321d-1231-dsad-652321829b50","emailAddress":"haris.h@dynatrace.com"}

Hello Haris,
Thanks, do you know if there are any permission to add to use this api ?
I’ve tried this url but I do get 403. Is there any specific scope that I should add to the platform token ?

Hi flomaz,

the permission should be app-engine:apps:run. Can you check if you have it?

Hi Haris,

Thanks, I’ve created a new platform token with the permission `app-engine:apps:run` and now I get a http 500.

{
“error”: {
“code”: 500,
“message”: “Internal Server Error occurred.”,
“details”: {
“errorRef”: “”,
“traceId”: “”
}
}
}

Hi flomaz,

thanks for the patience. We’re currently working on fixing this. I’ll update you as soon as I have new info.