Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
Hello,
I am attempting to secure my Web API connection in Power BI by taking my bearer token out of the M query using the ApiKeyName option in Web.Contents. I am able to connect to the dataset using this M query:
= Json.Document(Web.Contents(
"https://website.com",
[
Headers = [#"X-Authorization"="ABCD"],
RelativePath = "/api/blahblahblah"
]
))
But when I attempt to use this query:
= Json.Document(Web.Contents(
"https://website.com",
[
ApiKeyName= "X-Authorization",
RelativePath = "/api/blahblahblah"
]
))
...the authentication fails after entering the key under the "API Key" option in the credentials dialog box. What am I doing wrong here?
Solved! Go to Solution.
Hi @sean-hum,
I hope you are doing well today ☺️❤️
You are not doing anything wrong but also you are too close....but the ApiKeyName doesnt add the API key to request headers (It only tells Power BI the name of a query-string parameter (?api_key=something)
And your call is pssing the token as a header like this
Headers = [ #"X-Authorization" = "ABCD" ]Then when you switch to (ApiKeyName = "X-Authorization")....Power BI tries to send the key as ?X-Authorization=… in the URL and since the API expects it in the header authentication will fails that is why it breaks..You could find more about Web.Contents & PowerQueryM
So to solve this here is some Approaches you should try:
First Approach: If the API supports a query parameter
Json.Document(
Web.Contents(
"https://website.com",
[
RelativePath = "/api/blahblahblah",
ApiKeyName = "api_key" // whatever parameter name your API expects
]
)
)
Second Approach: If the API requires the key in a header (Thats is more Secure)
Thanks for the thorough reply!
Hi @sean-hum,
I hope you are doing well today ☺️❤️
You are not doing anything wrong but also you are too close....but the ApiKeyName doesnt add the API key to request headers (It only tells Power BI the name of a query-string parameter (?api_key=something)
And your call is pssing the token as a header like this
Headers = [ #"X-Authorization" = "ABCD" ]Then when you switch to (ApiKeyName = "X-Authorization")....Power BI tries to send the key as ?X-Authorization=… in the URL and since the API expects it in the header authentication will fails that is why it breaks..You could find more about Web.Contents & PowerQueryM
So to solve this here is some Approaches you should try:
First Approach: If the API supports a query parameter
Json.Document(
Web.Contents(
"https://website.com",
[
RelativePath = "/api/blahblahblah",
ApiKeyName = "api_key" // whatever parameter name your API expects
]
)
)
Second Approach: If the API requires the key in a header (Thats is more Secure)
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 56 | |
| 53 | |
| 40 | |
| 17 | |
| 16 |
| User | Count |
|---|---|
| 116 | |
| 107 | |
| 42 | |
| 33 | |
| 25 |