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 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"],
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- Anonymous9 years agoNot applicable
Hi,
We managed to get to conect to the api using PHP but wanting to do it in PowerBi. How would I go about translating
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.secondstreetapp.com/sessions"); //curl_setopt($ch, CURLOPT_URL, "https://www.google.com"); //$data = array("sessions"=>array("username"=>"****", "password"=>"***")); $data = '{"sessions":[{"username":"*****", "password": "*******"}]}'; curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json','Content-Type: application/json', 'X-Api-Key: *****')); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_VERBOSE, true); $session = curl_exec($ch); echo curl_error($ch); curl_close($ch); $sessionDecoded = json_decode($session); if ($campaignID == null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.secondstreetapp.com/message_campaigns?statusTypeId=1"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json','Content-Type: application/json', 'X-Api-Key: *****', 'Authorization:'.$sessionDecoded->sessions[0]->access_token, 'X-Organization-Id:'.$sessionDecoded->sessions[0]->organization_id)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_VERBOSE, true); $newsletters = curl_exec($ch); echo curl_error($ch); curl_close($ch); $newslettersDecoded = json_decode($newsletters); echo "<div class='list-group'>"; echo "<h1>Select a message</h1>"; foreach ($newslettersDecoded->message_campaigns as $campaign) { echo "<a href='index.php?campaignid=".$campaign->id."&messagetype=".$campaign->message_campaign_type_id."' class='list-group-item'>".$campaign->name."</a>"; }
- Anonymous9 years agoNot applicable
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