Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello,
I'm very new to working with Power Query when it comes to integrating with APIs. We have a platform that we use for which we're trying to get data from their API.
I've looked at some other posts on the community and the only that I've found that seems similar to my situation is the one below, however I have tried both the solutions on there and they result in the same issue.
https://community.powerbi.com/t5/Power-Query/Getting-data-from-API-with-JSON-body/m-p/1030682
I've put together a query using the same format as suggested on that post however I received the 'Web.Contents failed to get contents from 'URL' (400)' error. The query I've written is below:
let
url = "URL",
body = "{""since"": ""2021-01-01"",
""until"": ""2021-05-10"",
""channels"": [""200620789980139""],
""metrics"": [""page_impressions"",""page_engagement""],
""aggregation"": {
""unit"": ""day"",
""times"": 1,
""aligned"": false,
""firstdayofweek"": 1,
""function"": ""default""
}
}",
Source = Json.Document(Web.Contents(url,[
Headers = [#"Content-Type"="application/json"],
Content = Text.ToBinary(body)
]))
in
Source
The URL has to include the api key for authorisation and is included in this. I've also tried the same body content and URL on a website called reqbin and this brought up results when the call was made.
If you could please assist with how I can amend this query to get the data it would be a massive help. As I say, this is my first time working with APIs as a whole and the first time doing so in Power Query as well so much appreciated.
Solved! Go to Solution.
@Anonymous
I see no problem with code, the 400 bad request can be caused by different reason. It is hard to identify in this one. How to Fix a 400 Bad Request Error [Causes & Fixes] (kinsta.com)
There is a similar blog providing details about how to connect to REST API via OAuth2 in Power BI, you can following the instructions in this blog to connect to your data source.
If you still get error, you can use Fiddler to track like the post owner did in the link you provided.
Fiddler (Web Tracing) - YouTube
Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.
If you still get error, you can use Fiddler to track the process following the guide in this video.
@Anonymous
I see no problem with code, the 400 bad request can be caused by different reason. It is hard to identify in this one. How to Fix a 400 Bad Request Error [Causes & Fixes] (kinsta.com)
There is a similar blog providing details about how to connect to REST API via OAuth2 in Power BI, you can following the instructions in this blog to connect to your data source.
If you still get error, you can use Fiddler to track like the post owner did in the link you provided.
Fiddler (Web Tracing) - YouTube
Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.
If you still get error, you can use Fiddler to track the process following the guide in this video.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.