Forum Discussion
Connect to restful api data source multiple times
- Anonymous9 years ago
FYI we got it connecting using
let apiUrl = "https://api.secondstreetapp.com/sessions", data ="{'sessions':[{'username':'**', 'password': '**'}]}", options = [ Headers =[#"Content-Type"="application/json", #"X-Api-Key"="*****"], Content = Text.ToBinary(data) ], Value = Web.Contents(apiUrl,options), in Value
Hi Anonymous,
Add a new blank query in Power BI Desktop, then paste one of the following code in Advanced Editor and check if you get expected result.
let
Source = Json.Document(Web.Contents("your API address"), [Headers=[#" Authorization "="Your token"]])
in
Source
let
Source = Web.Contents("URL", [Headers=[#" Authorization " = "Your token"]])
in
Source
There are some blogs for your reference.
https://jessedotnet.com/2016/06/24/power-bi-connect-to-your-secure-api/
https://blog.crossjoin.co.uk/2014/03/26/working-with-web-services-in-power-query/
Thanks,
Lydia Zhang
Hi Lydia,
Thanks for getting back to me, the thing is though in order to get the token you have to first POST to the api.
Its like a two step authentication. How would this translate?
let
apiUrl = "https://api.secondstreetapp.com/sessions",
options = [Headers =[#"username"="***"],[#"password"="****"]],
result = Web.Contents(apiUrl , options)
in
result
When I put in the above I get Access to the resource is forbidden and then taken to a login screen, what I am needing it to return is...
{ |
Thanks
Chris
- Anonymous9 years agoNot applicable
Hi Anonymous,
What do you mean by "two step authentication"? If you refer to 2 factor authentication, as far as I know, Power BI doesn't support this auth method.
Thanks,
Lydia Zhang - hugoberry9 years agoResponsive Resident
Hi Chris try adding more options to your first request. Check the documentation maybe something like
#"Content-Type"="application/json"],
or
#"Accept"="application/json"],
Sometimes the REST endpoint don't know that the requests have to be JSON so they default to some basic authentication.
After you get your successful response from this request. Use the token from the response to construct another request with token already in the header
#"Autohrization"="token"],
- Anonymous9 years agoNot applicable
Thanks for replying guys and gals.
I aksed the company who responded with
The username and password aren't supposed to be headers, they are supposed to be part of a JSON body sent to the API. The headers required are as follows:
Content-Type:application/json
X-Api-Key:So I think you authenitcate after ?
- Anonymous9 years agoNot applicable
Hi Anonymous,
Please check the discussion in this simialr thread: https://community.powerbi.com/t5/Desktop/Get-data-from-web-error-A-web-API-key-can-only-be-specified-when/m-p/104101.
Thanks,
Lydia Zhang