Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Getting Data From POST API with JSON Body

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.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@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.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

@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.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.