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 registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
The Web.Contents function needs to specify content for making a POST request, but can`t get auth right. I pass the credentials (APIKey) and it works on Postman, but if I do it anonymous in PB it fails saying that can`t verify the credentials, but if I change it to basic auth PB tells me that the query needs to be from anonymous source. The code looks like this, the main part ends at JsonResponse, I don't think that the transformation of data matters for this problem.
Solved! Go to Solution.
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).
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.
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).
User | Count |
---|---|
16 | |
13 | |
12 | |
11 | |
10 |
User | Count |
---|---|
19 | |
16 | |
14 | |
11 | |
9 |