Main Content

Using Azure Active Directory

Get Group ID from Azure Active Directory Based on Group Display Name

  1. Sign in to Microsoft® Graph Explorer with your Azure® AD credentials:

    https://developer.microsoft.com/en-us/graph/graph-explorer

  2. Select GET as your HTTP query method.

  3. Specify the following query in the text box:

    https://graph.microsoft.com/v1.0/groups?$filter=startswith(displayName,'<groupname>')

    Replace <groupname> with the group name whose ID you are retrieving.

  4. Click the Run query button. The response includes a list of groups that match the display name you specified. Look for the id field in the JSON response to find the group's object ID. This is your group ID.

Example Query and JSON Response

Query:

https://graph.microsoft.com/v1.0/groups?$filter=startswith(displayName,'Finance')

Example JSON Response:

{
  "value": [
    {
      "id": "12345678-9abc-def0-1234-56789abcdef0",
      "displayName": "Finance Team",
      "mail": "financeteam@example.com",
      ...
    },
    {
      "id": "abcdef12-3456-7890-abcd-ef1234567890",
      "displayName": "Finance Department",
      "mail": "financedepartment@example.com",
      ...
    }
  ]
}

In this example, the id attributes ("12345678-9abc-def0-1234-56789abcdef0" and "abcdef12-3456-7890-abcd-ef1234567890") are the group IDs for the groups whose display names start with "Finance".

Get All Group IDs for a Certain User from Azure Active Directory

  1. Sign in to Microsoft Graph Explorer with your Azure AD credentials:

    https://developer.microsoft.com/en-us/graph/graph-explorer

  2. Select GET as your HTTP query method.

  3. Specify the following query in the text box:

    https://graph.microsoft.com/v1.0/users/<username>@<domain>/transitiveMemberOf

    Replace <username>@<domain> with the username and domain of the user whose group IDs you are retrieving.

  4. Click the Run query button. The response includes a list of directory objects that the specified user is a member of.

    • Look for objects where @odata.type is #microsoft.graph.group and securityEnabled is set to true.

    • The id attribute of these objects represents the group IDs.

Example Query and JSON Response

Query:

https://graph.microsoft.com/v1.0/users/johndoe@example.com/transitiveMemberOf

Example JSON Response:

{
  "value": [
    {
      "@odata.type": "#microsoft.graph.group",
      "id": "12345678-9abc-def0-1234-56789abcdef0",
      "displayName": "Group 1",
      "securityEnabled": true
    },
    {
      "@odata.type": "#microsoft.graph.group",
      "id": "abcdef12-3456-7890-abcd-ef1234567890",
      "displayName": "Group 2",
      "securityEnabled": false
    }
  ]
}

In this example, the group with id 12345678-9abc-def0-1234-56789abcdef0 has securityEnabled set to true, making it a relevant group ID for the user.

Note

The query uses transitiveMemberOf to fetch all groups a user is a member of, including nested groups. In MATLAB® Web App Server™, configure the groupAttributeName to groups to match the attribute used in the Microsoft Graph API response.

Related Topics

External Websites