Forum Discussion
Pull data from RESTful API with token authentication
- Anonymous9 years ago
Hi adam3039,
According to your description, you want to get the token of restful api, right?
You can write a power query function to get token,then use this function as the parameter to call the api.For detail information about get token, you can refer below article:
REST API Token-based AuthenticationCall API Sample:
let CallAPi= ( URI as text, Username as text, Token as text, Paremeter as table, optional Timeout as number ) as any => let WebTimeout = if Timeout = null then #duration(0,0,0,100) else #duration(0,0,0,Timeout) , WebServiceContent = function(Paremeter),//format parameters to content WebResponse = Web.Contents(Username&":"&Token&URI, [Content = Text.ToBinary(WebServiceContent), Headers = [Authorization="xxxxx", #"Content-Type"="application/json", Accept="application/json"], Timeout = WebTimeout]), output = formatfunction(WebResponse) //format the response in output in CallAPiRegards,
Xiaoxin Sheng
Does the key change upon each refresh of the data or does it remain static for every session?
hi Breticious,
Thank you for the reply,ofcourse the key will change every time(Whenever the user login new token will generate)
- Breticious8 years ago
Helper I
Unfortunately, your situation is likely to differ greatly from the rest of our situations since most API creators do not follow the same protocols as others. This inconsistency is good in the sense of bots having a harder time breaking through but in turn makes it very difficult for new coders to modify something they don't fully follow.
You need to describe your scenario much more deeply.
1. How do you get authentication code?
2. Do you have a code given to you by the vendor that must be passed through to get the authentication code?
3. Once you have the code, where do you put it when passing it through to the GET web address? The header, the body, etc.?
4. If it goes in the header, what is the value named?
5. What is the content format of your request?
6. What is the request call to the GET address?
I cannot just give you my code's scenario because I can almost guarantee that it is NOT going to fit your scenario just as the author of this post's scenario did not fit mine. The modifications I made to my code does not resemble the code above whatsoever now.
- Anonymous8 years agoNot applicable
Hi Breticious,
Thank you for the quick reply.
Let me explain my scenario.
I need to get the Data from the following API bijuapidev.bijuwatch.com/api/GlobalSearch/GetOrders and which is having a token that is usually generate while login http://bijudev.bijuwatch.com/login.html. So i have to get this dynamic token in power bi and show the data.
Hope its clear for you.
Thank you.
- Breticious8 years ago
Helper I
Bijay:
Ok. We're getting closer. Do you have a sample of code provided by the vendor in javascript?
I understand what's going on, but we are still missing information.
- Where do you pass the retreived one-time auth key through in the GET call? A lot of times it goes through in the header but should anything else be in the header? In my scenario, I was able to get this information from sample code my vendor provided in Javascript.
- Are there anymore paramaters required in your GET?
- Should there be anything in the body of the GET or should it be blank?
- What type of data is supposed to come back to you once you successfully authenticate?
There were several things that it expressly wanted in a very very specific format. Your scenario sounds a bit simpler, but we still need more information!