cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dheer1688 Regular Visitor
Regular Visitor

API Key Authentication Problem

I'm using API key for fetching data, My Api key expires in every 10 days so I define key in parameter .

web: https://MyUrl.com?Token={Key}

Everything working fine on dextop, but when I go to schedule refresh on web secrvice it shows me invalid credentials.

 

So I click on edit credentials.

Where i can see Url: & Authentication Method: 
I'm not allowed to edit URL part so I copied url and paste in notepad. I found API is attached in URL but when I closely see the API is diffrent which I pass in parameter.

 

How can I remove API key in Url part ? Or is there any other way to use API.

Capture.JPG

Thanks in advacne ..

7 REPLIES 7

Re: API Key Authentication Problem

Hi @dheer1688,

 

Take a look in your query from the advanced editor. You should make sure you are not using the key in your url. You can instead use this in the option as seen from link below:

 

https://jessedotnet.com/2016/06/24/power-bi-connect-to-your-secure-api/

dheer1688 Regular Visitor
Regular Visitor

Re: API Key Authentication Problem

Hi @richardlhughes thanks for reply.

 

I'm new to power BI and very less knowledge about API.

So, my  advance editor code: 

 

let

Source = Json.Document(Web.Contents("https://re-client-proxy.TEST.XXYY.com/reporting/v3/state?token=KEY")),
 #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Err

 

in


 #"Converted to Table"

 

 

 

I tried to convert this into format as website described but ended up with:

" We couldn't authenticate with credentials provided." I select every option from drop down but it failed to pass.

 

let
apiUrl = "https://re-client-proxy.TEST.XXYY.com/reporting/v3/State?",
options = [Headers =[#"token"="KEY"]],
result = Web.Contents(apiUrl , options)
in
result

 

 

Re: API Key Authentication Problem

Hi @dheer1688,

 

See if this helps at all from my example below:

 

let
    Source = Json.Document(Web.Contents("https://www.myurl.com/",
[Query=[#"fields"="[briefDescription,parentIds]"],
Headers=[#"Authorization"="bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"],
RelativePath="/api/v3/tasks"
]
)),
data = Source[data],

 

Your query should look something like this:

 

let
Source = Json.Document(Web.Contents("https://re-client-proxy.TEST.XXYY.com",
RelativePath="/reporting/v3/state",
Headers=[#"TOKEN"="KEY"])),
 #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error)

 
in

 #"Converted to Table"

dheer1688 Regular Visitor
Regular Visitor

Re: API Key Authentication Problem

Hi @richardlhughes 

Thanks for reply,

 

I used your query but getting error.

Capture.PNG

 

So when I click to Go to error, its showing "Expression.Error: The name 'RelativePath' wasn't recognized.  Make sure it's spelled correctly."

 

So I add "[]" in your query highlighted with red and again end up in credentials invalid"

 

let
Source = Json.Document(Web.Contents("https://re-client-proxy.xxx.com",
[RelativePath="/reporting/v3/state",
Headers=[#"TOKEN"="KEY"]]
)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error)


in

#"Converted to Table"

 

Re: API Key Authentication Problem

I would reccommend using Fiddler to debug your web calls at this point.

 

You can acutally see the traffic that is getting sent to your web service. Compare the calls from Power BI and the known good source.

dheer1688 Regular Visitor
Regular Visitor

Re: API Key Authentication Problem

Hi @richardlhughes

 Thanks for reply.

 

I don't have knowledge abt Fiddler, but I'm  doing R&D with fiddler. 

 

I asked my dev. to convert web address to Curl, so that I can find which header he is using for token. But I didn't find any header for token. Is it right way to attach token with add.

 

@richardlhughes do you think this is y, I fnd token in URL while setting schedule refresh and Because of that when token expires in 10 days schedule refresh not working as old token still there in URL even after I've updated token in desktop. 

 

curl --header 'accept: application/json' --header 'content-type: application/json' https://re-client-proxy.prod.XXXYY.com/reporting/v3/State?token=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJtZW5...

Re: API Key Authentication Problem

If your token is only good for 10 days you need to setup the data connection to refresh the token.

 

Here is a example how Micorsoft oauth2 works:

 

https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-...

 

This might be a good starting point.