Forum Discussion
POST request with Power Query fails auth but needs to be Anonymous
- 2 years ago
Hi Nono, thx for the help. I was close enough, i just needed to ajust my query. This is the solution I got, the apiKey is in the body because I did it with x-www-form-urlencoded, from my testing in Postman (because this is a call to a custom function in an API).
ā
Hi JangoChained
In Power BI, when issuing a POST request using this function, you need to ensure that the API key is properly included in the header.
If you are using the API key for authentication, you typically need to include it in the request's header.
Here is an example of how to use the header constructor:
let
url = "Your_API_Endpoint",
body = "Your_Body_Content",
apikey = "Your_API_Key",
headers = [#"Content-Type"="application/json", #"Authorization"= "Bearer " & apikey],
Source = Json.Document(Web.Contents(url, [Headers=headers, Content=Text.ToBinary(body)]))
in
Source
The HTTP request is made as either a GET (when no Content is specified) or a POST (when there is Content). POST requests may only be made anonymously.
Web.Contents is used for retrieving web content that doesn't need to be accessed through a browser, such as CSV files, JSON API results, and so on.
You can view the link below for more details:
Web.Contents - PowerQuery M | Microsoft Learn
Troubleshooting the Power Query Web connector - Power Query | Microsoft Learn
You can post in the Power Query forum so you can get more professional help.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- JangoChained2 years agoFrequent Visitor
Hi Nono, thx for the help. I was close enough, i just needed to ajust my query. This is the solution I got, the apiKey is in the body because I did it with x-www-form-urlencoded, from my testing in Postman (because this is a call to a custom function in an API).
ā