At the moment I want to use the Graph API for an application that will list all the tenants, get all users per tenant and then list all their licenses. Due to circumstances I can only use the web calls, no Powershell modules or any of the sort.
I found that you should be able to do this in Graph (https://learn.microsoft.com/en-us/graph/api/managedtenants-managedtenant-list-tenants?view=graph-rest-beta&tabs=http) except it's only allowed for delegated permissions and in the beta.
So I searched for an alternative for which seemed to be the management.azure.com API (https://learn.microsoft.com/en-us/rest/api/resources/tenants/list?view=rest-resources-2022-12-01&tabs=HTTP#code-try-0) but I can't for the life of me figure if this one is getting deprecated alongside all the other recent API stuff getting deprecated. I'm also not clear if this one is only delegated permissions aswell.
Can you guys confirm? Or any other tips to get the functionality what I need? Many thanks
To list the tenants without user interaction, check the below:
Create a Microsoft Entra ID application and grant API permissions:
Generate the access token via Client Credential flow:
https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
client_id:ClientID
client_secret:ClientSecret
scope:https://management.azure.com/.default
grant_type:client_credentials
By using the above access token, you can call the API to list the tenants:
https://management.azure.com/tenants?api-version=2022-12-01