cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TuanPham1999
Frequent Visitor

Pull data from API using POST method in Power BI

Hi all, I'm a fresher in Power BI Desktop. my mission is extract data from given credentials include: ClientID, Password and Url. The credentials must be Base64 encoded for use in the POST /oauth2/token request. I have used that credentials in Postman and I got its header such as: Authorization: Basic xxxxxxxxxxxxxxxxxxxxxx. what should i start with all of them to get data from API. Can anyone help me to solve this probleml. thank you so much for any solution and suggestion. Cheer!!!

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@TuanPham1999,

 

You may refer to the following post.

https://community.powerbi.com/t5/Desktop/Connect-to-a-Web-Service-sending-parameters/td-p/225510

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

I found it not so easy to get data via POST so I am pasting here what I did in case this helps someone else in the future.

 

I created the following blank query:

 

= let
   body = "The POST method body here",
   Data= Web.Contents("https://yourusrlhere",[Content=Text.ToBinary(body),Headers=[#"Content- 
   Type"="application/json"]]),
   DataRecord = Json.Document(Data),
   Source=DataRecord 
in
   Source

 

 

I wanted to post a more complete/cleaner version of the above solution that contains multiple headers and shows how to convert the body to binary data for POST operations: 

 

let
    url = "https://api.somevendor.com/api/",
    headers = [#"Content-Type" = "application/x-www-form-urlencoded", #"Accept" = "application/json"],
    postData = "Any sort of text data you want to post to the API",
    response = Web.Contents(
        url,
        [
            Headers = headers,
            Content = Text.ToBinary(postData)
        ]
    ),
    jsonResponse = Json.Document(response)
in
    jsonResponse

 

What  body = "The POST method body here", is for?

 

Thanks

TuanPham1999
Frequent Visitor

Hi all, I'm a fresher in Power BI Desktop. my mission is extract data from given credentials include: ClientID, Password and Url. The credentials must be Base64 encoded for use in the POST /oauth2/token request. I have used that credentials in Postman and I got its header such as: Authorization: Basic xxxxxxxxxxxxxxxxxxxxxx. what should i start with all of them to get data from API. Can anyone help me to solve this probleml. thank you so much for any solution and suggestion. Cheer!!!

v-chuncz-msft
Community Support
Community Support

@TuanPham1999,

 

You may refer to the following post.

https://community.powerbi.com/t5/Desktop/Connect-to-a-Web-Service-sending-parameters/td-p/225510

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
October 2023 Update

Power BI October-2023 Update

Take a look at the 2023 October Power BI update to learn more.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.