简体   繁体   中英

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

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

在此处输入图片说明

The DisplayName is the tenant name.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM