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

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.

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
V-pazhen-msft
Community Support
Community Support

@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
V-pazhen-msft
Community Support
Community Support

@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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors