# Gather groups from user inside an APP

**URL:** <https://community.dynatrace.com/t/gather-groups-from-user-inside-an-app/49757>\
**Category:** Developer Q&A Forum\
**Tags:** custom-app, app-functions\
**Created:** [January 16, 2025, 12:29pm UTC](https://community.dynatrace.com/t/gather-groups-from-user-inside-an-app/49757 "2025-01-16T12:29:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![david\_lopes](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/david_lopes/32/27273_2.png) [@david\_lopes](https://community.dynatrace.com/u/david_lopes)\
**Post date:** [January 17, 2025, 12:48am UTC](https://community.dynatrace.com/t/gather-groups-from-user-inside-an-app/49757/2 "2025-01-17T00:48:27Z")

</div>

I’ve had to do something similar in the past  
The only way to get group information is by using the IAM APIs, they are not part of the platform

So you will need to:

1. Write a client to access the IAM data

Luckily there is a swagger documentation here: [Dynatrace Account Management API](https://api.dynatrace.com/spec/)

So you can easily create a client by running

```markup
npx swagger-typescript-api --modular --single-http-client --extract-response-body -p https://api.dynatrace.com/spec-json -o account-management

```

2. Write an app function to retrieve the list of groups

You will need to use an app function because you won’t be able to access the account management API directly from the  
browser

And you are correct, you WILL need to provide the oauth client details and account id

Here is a function that that app function can call to get the groups for a user:

```javascript
/**
 * Get all groups for a user
 * @param {Iam} iam - The Iam object, used to make API calls
 * @param {string} email - The user email
 * @param {string} accountUuid - The account UUID
 * @returns {UserGroupsEntry} - A UserGroupsEntry object
 */
async function getUserGroups(
  iam: Iam,
  email: string,
  accountUuid: string
): Promise<UserGroupsEntry> {
  return await iam
    .usersControllerGetUserGroups(accountUuid, email)
    .then((response) => {
      return { email: email, result: ok(response.data) };
    })
    .catch((error: ApiError) => {
      let errorMessage = `Error retrieving data: ${error}`;
      if (error.error !== undefined && error.error.message !== undefined) {
        errorMessage = error.error.message;
      }
      return { email: email, result: err(new Error(`${errorMessage}`)) };
    });
}

```

You will need to ask for the account UUID, there is no way to retrieve this information from the app.  
I suggest creating an [app setting schema](https://developer.dynatrace.com/develop/data/store-app-settings/) for your app, with the properties:

```javascript
{
    "name": {
      "displayName": "Connection name",
      "description": "The name of these credentials",
      "documentation": "",
      "type": "text",
      "nullable": false,
      "default": "",
      "constraints": [
        {
          "type": "NOT_BLANK"
        }
      ]
    },
    "clientId": {
        "displayName": "Client ID",
        "description": "The [OAuth2 Client ID](https://www.dynatrace.com/support/help/shortlink/account-api-authentication#create-an-oauth2-client)",
        "type": "text",
        "nullable": false,
        "default": "",
        "constraints": [
            {
            "type": "NOT_BLANK"
            }
        ]
    },
    "clientSecret": {
        "displayName": "Client Secret",
        "description": "The [OAuth2 Client Secret](https://www.dynatrace.com/support/help/shortlink/account-api-authentication#create-an-oauth2-client)",
        "type": "secret",
        "nullable": false,
        "default": "",
        "constraints": [
            {
            "type": "NOT_BLANK"
            }
        ]
    },
    "accountUuid": {
        "displayName": "Account UUID",
        "documentation": "You can find the UUID on the `Account > Account management API` page, during creation of an OAuth2 client.",
        "type": "text",
        "nullable": false,
        "default": "",
        "constraints": [
            {
            "type": "PATTERN",
            "pattern": "^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$"
            }
        ]
    }
}

```

---

_[View the full topic](https://community.dynatrace.com/t/gather-groups-from-user-inside-an-app/49757)._
