1
votes

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

2

2 Answers

2
votes

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.

0
votes

The main endpoint is https://graph.microsoft.com/v1.0/organization

Sample code (Node.js):

const info_tenant = await apiRequestFunction(`https://graph.microsoft.com/v1.0/organization`, 'GET', null, {
      "Authorization": access_token,
      "Content-Type": "application/json"
});

returns organisation information where info_tenant.value[0].displayName is tenant name.