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
bixam88
Regular Visitor

WebAPI using POST method to pull data from API

Hi,

I'm trying to get a POST method to work with WebAPI but it's throwing below the errosr that I tried with 2 parameters. It's working completely fine on Postman. 

 

Method 1 using X-ApiKey Authentication without Content=Text.FromBinary("") :

let
Http_query = Web.Contents("https://api.website.com/api/GetAllProfiles",
[Headers=[#"X-ApiKey"="<ApiKey>",
#"Content-Type"="application/json"]])
in
Http_query

 

ERROR:

DataSource.Error: Web.Contents failed to get contents from 'https://api.website.com/api/GetAllProfiles' (405): Method Not Allowed

 

 

Method 2 using X-ApiKey Authentication with Content=Text.FromBinary("") :

let
Http_query = Web.Contents("https://api.website.com/api/GetAllProfiles",
[Headers=[#"X-ApiKey"="<ApiKey>",
Content=Text.FromBinary(""), #"Content-Type"="application/json"]])
in
Http_query

 

ERROR:

Expression.Error: We cannot convert the value "" to type Binary.
Details:
Value=
Type=[Type]

 

 

Postman Authorization screenshot adding for reference where it's showing the results as required.

bixam88_1-1656189138069.png

 

Any help would be appreciated to rectify this issue. Thanks

 

6 REPLIES 6
otravers
Community Champion
Community Champion

The first one won't work as Web.Contents need you to specify Content to POST, without it the function defaults to GET:

https://docs.microsoft.com/en-us/powerquery-m/web-contents

 

The second one doesn't work because you're not specifying where the binary is coming from.

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals

@otravers i also tried another method to authenticate via Body which is also working fine on Postman but throws error in Power Bi as commented below. Any help on that will be helpful.

otravers
Community Champion
Community Champion

The Body would typically be some payload (e.g. a JSON array) that your API is expecting in the POST:

https://eriksvensen.wordpress.com/2014/09/15/specifying-json-query-in-power-query-example-statistics...

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals

@otravers  What should i add in (Body) since i am getting error if i use below query:

May you could rewrite this to better clairfy. Thanks

 

let
Http_query = Web.Contents("https://api.website/api/GetAllProfiles",
[Headers=[#"X-ApiKey"="<ApiKey>",
Content=Text.FromBinary(Body), #"Content-Type"="application/json"]])
in
Http_query

 

Error

Expression.Error: The name 'Body' wasn't recognized. Make sure it's spelled correctly.

otravers
Community Champion
Community Champion

Sorry that was poorly phrased. I'm running out so can't go into details, but you need to specify something in the Text.FromBinary() part.

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals

@otravers 
I also tried another method to authenticate via Body which is also working fine on Postman but throws error in Power Bi as shown below:


Body=
[
#"apiKey"= "<ApiKey>"
],

webdata = Web.Contents("https://api.website.com/api/Profile/GetAllProfiles",

[Headers=[#"Content-Type"="application/json"],
Content=Text.FromBinary(Body)

])
in
webdata

 

Error:

Expression.Error: We cannot convert a value of type Record to type Binary.
Details:
Value=
apiKey=<ApiKey>
Type=[Type]

 

Screenshot from Postman

bixam88_0-1656250734151.png

 

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.