-1

I have the following API CURL below

curl -u API_KEY:API_SECRET https://api.mysite.com/v1/test

please how do I set and send the value of API_KEY:API_SECRET in the curl request below

<?php


$link ="https://api.mysite.com/v1/test";
$curl=curl_init(); 
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_URL,$link);
curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt($curl, CURLOPT_HTTPHEADER, array("accept: application/json"));  
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,1);
//curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
$out = curl_exec($curl); 
curl_close($curl);
var_dump($out);

?>
Henrymart
  • 122
  • 1
  • 9
  • Might the API expect an authorization header? See: [How do I make a request using HTTP basic authentication with PHP curl?](https://stackoverflow.com/questions/2140419/how-do-i-make-a-request-using-http-basic-authentication-with-php-curl) – showdev Nov 18 '19 at 03:51
  • CURLOPT_USERPWD – nomistic Nov 18 '19 at 04:01

1 Answers1

0

You just need to send your api key and secret using CURLOPT_USERPWD, like so

curl_setopt($curl, CURLOPT_USERPWD, 'API_KEY:API_SECRET');
nomistic
  • 2,902
  • 4
  • 20
  • 36