· Dan · Microsoft  · 2 min read

Resolve Microsoft Subscription ID to Tenant ID

n8n-nodes-base.httpRequest @mspcopilot/n8n-nodes-microsoft-partner-gdap.microsoftPartnerGdap

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

  1. n8n-nodes-base.httpRequest Resolve Subscription ID (ARM call):
    • Makes a GET request 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 Unauthorized and includes a WWW-Authenticate header that contains the tenant ID: authorization_uri="https://login.windows.net/{tenantId}".
  2. Set tenantId:
    • A Set node parses the WWW-Authenticate header with a regex and extracts the tenant ID into tenantId. {{ $json.headers['www-authenticate'].match(/https:\\/\\/login\\.windows\\.net\\/([0-9a-f-]{36})/i)?.[1];\n }}
  3. @mspcopilot/n8n-nodes-microsoft-partner-gdap.microsoftPartnerGdap 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, and verifiedDomains for the tenant.
  4. @mspcopilot/n8n-nodes-microsoft-partner-gdap.microsoftPartnerGdap Get User Example (optional):
    • Shows how to reuse the same tenant context to call /v1.0/users in Microsoft Graph for that tenant.

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.