Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredJoin us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered
Hello Power BI / Fabric / Power Query Community,
I'm working on a Dataflow Gen2 in Microsoft Fabric to connect to a REST API that requires dynamic Bearer token authentication. I'm hitting a wall with how Power Query handles the Authorization header, especially when the web connection is set to "Anonymous." I've been going in circles with various error codes, and I'm hoping someone has encountered this and found a robust solution or best practice for Dataflow Gen2.
My Goal:
My Setup:
Environment: Microsoft Fabric Dataflow Gen2.
Login M Function (GetToken): This function successfully retrieves the Bearer token using Basic authentication. (It uses Authorization = "Basic ...")
Extrait de code
let
// Assuming USER, PASSWORD, URL are defined
combined= Text.ToBinary(USER & ":" & PASSWORD),
encoded = Binary.ToText(combined, BinaryEncoding.Base64),
authHeader = "Basic " & encoded,
Source = () => // This function correctly returns "Bearer
<token>"
let
requestOptions = [
Timeout = #duration(0, 0, 1, 0),
Headers = [
Authorization= authHeader,
#"Content-Type" = "application/json"
]
],
response = Web.Contents(URL & "/app/rest/login",requestOptions),
data = Json.Document(response, 65001),
records = Table.FromRecords({data}),
expandedTable = Table.ExpandRecordColumn(records, "data", {"token"}, {"data.token"}), firstValue = Table.FirstValue(expandedTable)
in
"Bearer " & firstValue
in
Source
Data Retrieval M Function (Source): This function is supposed to use the token from GetToken().
Web Data Source Configuration (in Dataflow Gen2 UI): The connection is set to "Anonyme" (Anonymous).
Error & My Attempt:
// Code in Source function, after previous fixes
requestOptions = [
Headers = [#"Content-type"="application/json", #"Authorization" = GetToken()],
],
response = Web.Contents(fullUrl, requestOptions),
Persistent Error: "Authorization" header restricted (ErrorCode 10348 - Contradictory!)
Even with #"Authorization" = GetToken(), the same ErrorCode 10348 persisted, with a new message:
Expression.Error: "The 'Authorization' header is only supported during anonymous connection. These headers can be used with all authentication types: Accept, Accept-Charset, ...")
This is the core paradox: it states Authorization is only supported for anonymous, but then throws an error when my connection is anonymous.
Any insights or guidance would be greatly appreciated!
Thank you!
Hi @hajar_bkg,
Thank you for the detailed explanation and context. You're on the right track, but you've encountered a known limitation in Fabric Dataflow Gen2.
Dynamic Authorization headers, even with anonymous connection mode, are currently not supported in Dataflows Gen2 due to platform-level security restrictions. This is why your approach using #"Authorization" = GetToken() is causing the Expression.Error.
The recommended solution is to shift token-based logic to a proxy service (such as an Azure Function or Power Automate flow) that manages authentication and returns clean JSON data. Your Dataflow can then connect to that service anonymously and securely.
This limitation is acknowledged by Microsoft, and improvements may be forthcoming. For now, using a proxy service is the most reliable and scalable workaround.
Solved: Re: API in dataflowgen2 - Microsoft Fabric Community
I hope this helped! Feel free to ask any further questions. If this resolved your issue, please mark it as "Accept as Solution" and give us Kudos to assist others.
Thank you,
Sahasra
Communtiy Support Team.
Hi @hajar_bkg,
Hope you're doing well! Just following up to see if the response we shared was helpful. If you have any further questions or need clarification, we’re here to assist.
If your issue is resolved, please consider marking the answer as Accepted and giving it a Kudos to help others in the community.
Thanks for being a part of the Microsoft Fabric Community!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
13 | |
4 | |
3 | |
3 | |
3 |
User | Count |
---|---|
8 | |
8 | |
7 | |
6 | |
5 |