Search code examples
azureazure-ad-graph-apimicrosoft-entra-id

How to get all directories Microsoft Entra user is part of?


We want to find the directory details in which user is a member. In Portal, these are found in Directories + Subscriptions tab. How to get the same details using Azure API? We found this API but getting only one organisation GET https://graph.microsoft.com/v1.0/organization Is there a way for all organization's details in one API call? Thanks, Damodhar


Solution

  • Note that, you cannot get all the organizations details using Microsoft Graph API. Alternatively, you can use Azure Management API to fetch all the organizations associated to your account.

    I registered one Azure AD application and granted below API permission in it:

    enter image description here

    Now, I generated access token using username password flow via Postman with below parameters:

    POST https://login.microsoftonline.com/tenantId/oauth2/v2.0/token
    grant_type:password
    client_id: appId
    client_secret: secret 
    scope: https://management.azure.com/.default
    username: admin@xxxx.onmicrosoft.com
    password: xxxxxxxxx
    

    Response:

    enter image description here

    When I ran below Azure Management API call with generated token, I got list of organizations successfully as below:

    GET https://management.azure.com/tenants?api-version=2022-12-01
    

    Response:

    enter image description here

    Reference: Tenants - List - REST API (Azure Resource Management) | Microsoft