· Dan · Microsoft · 2 min read
Resolve Microsoft Subscription ID to Tenant ID
Use an unauthenticated Azure API call to resolve any Azure subscription ID to its tenant ID.
Overview
This workflow takes an Azure Subscription ID and resolves it to the owning Microsoft Entra (Azure AD) tenant, returning the Tenant ID, Display Name, and Default Domain.
It uses a clever trick: an unauthenticated Azure Resource Manager (ARM) request that intentionally fails with 401 to discover the tenant ID, optionally calling the Microsoft Graph API to fetch public tenant information or perform other operations.
This is ideal for MSPs who regularly receive subscription IDs (from logs, invoices, alerts, etc.) and need to quickly determine which tenant they belong to.
The Workflow
How It Works
-
Resolve Subscription ID (ARM call):
- Makes a
GETrequest to:https://management.azure.com/subscriptions/{{ $json.subscriptionId }}?api-version=2020-01-01 - The call is unauthenticated on purpose.
- It is set to Never Error and Include Response Headers and Status.
- Azure responds with
401 Unauthorizedand includes aWWW-Authenticateheader that contains the tenant ID:authorization_uri="https://login.windows.net/{tenantId}".
- Makes a
- Set tenantId:
- A Set node parses the
WWW-Authenticateheader with a regex and extracts the tenant ID intotenantId.{{ $json.headers['www-authenticate'].match(/https:\\/\\/login\\.windows\\.net\\/([0-9a-f-]{36})/i)?.[1];\n }}
- A Set node parses the
-
Lookup Tenant Details (Graph):
- Uses the Microsoft Partner GDAP node to call:
https://graph.microsoft.com/v1.0/tenantRelationships/findTenantInformationByTenantId(tenantId='{{ $json.tenantId }}') - Returns
displayName,defaultDomainName, andverifiedDomainsfor the tenant.
- Uses the Microsoft Partner GDAP node to call:
-
Get User Example (optional):
- Shows how to reuse the same tenant context to call
/v1.0/usersin Microsoft Graph for that tenant.
- Shows how to reuse the same tenant context to call
Credits
This workflow is based on a great idea shared in the r/MSP community.
Special thanks to u/olavhell for the original concept and inspiration.