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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
Anonymous
Not applicable

Rest API Authentication API-Key

Hey guys, 

 

so I'm new into power bi and the power query m language and never worked with that.

Basically I'm trying to connect a rest api with my power bi.

In order to get the data, I'll have to perform a POST call with a api key to obtain a beaerer token.

 

My approach was to use the advanced editor with the web.contents function. But I always get the error "(404) Not found"

Could u guys take a look at my function?

 

let

GetJson = Web.Contents("URL", [Headers=[#"Content-Type"="application/json", #"X-API-Key"="ABC"]])
in

GetJson

 

Ps: the endpoint works fine, I tried it on postman and got the bearer token.

I just cant obtain it on power bi.

2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

If the API requires a POST call then you need to put the data in the body, not the header.  Consult the API documentation, and then use Json.FromValue() to binary encode the payload.

 

Like so:

let
    URL = "http://xxx/tstat",
    headers = [#"Content-Type"="application/json"],
    data = Json.FromValue([tmode = 2,t_cool = Setpoint,hold = 0]),
    web = Web.Contents(URL, [ Content = data, Headers = headers, ManualStatusHandling = {404, 400}]),
    result = Json.Document(web),
...

View solution in original post

you are missing the quotes around the key

 

data = Json.FromValue([apiKey = "123ABC"]),

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

If the API requires a POST call then you need to put the data in the body, not the header.  Consult the API documentation, and then use Json.FromValue() to binary encode the payload.

 

Like so:

let
    URL = "http://xxx/tstat",
    headers = [#"Content-Type"="application/json"],
    data = Json.FromValue([tmode = 2,t_cool = Setpoint,hold = 0]),
    web = Web.Contents(URL, [ Content = data, Headers = headers, ManualStatusHandling = {404, 400}]),
    result = Json.Document(web),
...
Anonymous
Not applicable

Hi Ibendlin,

 

do you mean that I have to put my apikey into the Json.FromValue function?

 

let
URL = "URL",
headers = [#"Content-Type"="application/json"],
data = Json.FromValue([apiKey = 123ABC]),
web = Web.Contents(URL,[ Content = data,Headers = headers, ManualStatusHandling = {404, 400}]),
result = Json.Document(web)
in
result

It gives ma an error, my api key is mixture of letters and numbers. 

 

my API documentation says: 

 

HTTP Method

POST

Query

A json object contaaining only the "apiKey" field inside.

 

body: {

apiKey: "xxxxx"

}

you are missing the quotes around the key

 

data = Json.FromValue([apiKey = "123ABC"]),

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Kudoed Authors