Forum Discussion

acanepa's avatar
acanepa
Icon for Resolver I rankResolver I
6 years ago

X-API-KEY outside Headers

Hello,

 

I'm connecting to an API that has Oauth2, and so far I have been able to connect using a Refresh Token as a parameter. The problem with this is not safe, because the parameter is exposed in PowerBI service.

I'm trying to use X-API-KEY outside the headers but seems PowerBI doesn't recognize the "X-API-KEY"

 

For example, if I put X-API-KEY into a string

 

content = "{
""grant_type"":""refresh_token"",
""refresh_token"": "&X-API-KEY&",
}",

Headers_accesstoken =     [Headers=[#"Content-Type"="application/json" ],Content=Text.ToBinary(content)],
AccessToken = Json.Document(Web.Contents("https://my_url.com/oauth/token",Headers_accesstoken))[access_token],

 

 

In this case, the API KEY has to be generated and cannot be provided once because it will expire quite rapidly.

 

I can also work with User and Password outside the headers as well.

 

The access Token is used like this:

 

options = [Headers =[Authorization="Bearer " & AccessToken]],
API_CALL = Json.Document(Web.Contents("myurl.com/action", options))

 

2 Replies