1

The company where I make an api call to changed there authentication to basic authentication. Here's there api documentation about this issue:

your partner code is "apiuser", secret key is "apipass".

Username is "apiuser". Password is "apipass". Basic auth string is Base64("apiuser:apipass") = "YXBpdXNlcjphcGlwYXNz=". Authentication header is "Authorization: Basic YXBpdXNlcjphcGlwYXNz=".

My current code is doing nothing so I don't know what i'm doing wrong?

$apiuser = "apiuser";
$apipass = "apipass";
$username = $apiuser.'-'.time();
$password = hash_hmac('sha1', $username, $apipass);
$basic_auth = base64_encode($username.":".$password);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept:application/json", "Authorization: Basic $basic_auth"));
curl_setopt($ch, CURLOPT_URL, 'http://examppleurl.com/api/v2/places?holiday_type='.$hotel_types_name.'&currency=EUR&checkin='.date('Y-m-d', strtotime("+1 days")).'&checkout='.date('Y-m-d', strtotime("+1 days")).'&groups[]=1');//&groups[]=2,10,12&location=Turkey
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch);
curl_close($ch);
$obj = json_decode($result);
Bill Hileman
  • 2,798
  • 2
  • 17
  • 24
NUBG
  • 11
  • 1
  • Look here maybe ? [https://stackoverflow.com/questions/2140419/how-do-i-make-a-request-using-http-basic-authentication-with-php-curl]. Might be easier to use: curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); , but read the post. – SScotti Jun 27 '19 at 00:39
  • From the documentation you provided it looks like the username and password are just used as strings, so are you sure you need to generate something else for the $username and $password variables?? – David Jul 03 '19 at 14:45

0 Answers0