azureazure-active-directoryazure-management-apiazure-management

How to find out the tenant name using REST API


Is there an API that can be used to get the tenant name where a resource is? I know the resource group and the subscription.

All that I found so far is a way to list all the tenants https://management.azure.com/tenants?api-version=2017-08-01 but i still don't know how to connect this info with an Azure resource


Solution

  • AFAIK, if you want to use rest api to do that, seems we could just use the MS graph api : Get organization or the AAD graph GET https://graph.windows.net/{tenant id}/tenantDetails?api-version=1.6 to get the tenant name, but it just get the currently authenticated tenant.

    If you want to the tenant name via a resource, you could use azure powershell to do that. As you know the subscription, specific the -SubscriptionId with which subscription the resource in.

    $TenantId = (Get-AzureRmSubscription -SubscriptionId "xxxx").TenantId
    Connect-AzureAD -TenantId $TenantId
    Get-AzureADTenantDetail
    

    enter image description here

    The DisplayName is the tenant name.