The problem/error/question
I’m trying to loop through multiple Microsoft Entra tenants (customers) in n8n and retrieve license usage (or perform other tenant-scoped Graph operations) using client credentials.
I’ve created a Generic OAuth2 credential where the Access Token URL is set using an expression:
https://login.microsoftonline.com/{{$json["id"]}}/oauth2/v2.0/token
The credential uses a multi-tenant Enterprise Application (client ID + secret), and the workflow loops over tenant IDs using Split in Batches.
The issue I’m seeing is that only the first iteration of the loop evaluates the expression. After that, the credential appears to cache the token and/or token URL, so all subsequent requests use the same tenant’s access token, even though the input item ($json["id"]) changes.
My expectation is that for each loop iteration, the OAuth credential would:
-
Re-evaluate the Access Token URL expression
-
Request a new token scoped to the current tenant ID
Instead, it behaves as if the credential is evaluated once per workflow execution.
Is this:
-
A known limitation of OAuth credentials (expressions evaluated once)?
-
Token caching behaviour by design?
-
Or a bug?
A similar issue was discussed here but never resolved: Expression in credentials - only uses first item
Workflow:
Information on n8n setup
- n8n version: 2.1.5
Thanks in advance for any assistance!