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
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 ?
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- Anonymous8 years agoNot applicable
how did you set your credentials? as anonymous?
I have a similar API but it seems it is not accepting my username and password parameters.When I use anonymous, I get error. When I use basic auth (with pop up box), I get error from web.content only possible when anonymous...