I try to make HTTP request to my vendor API using curl Basic Auth like this :
//Server url
$url = "https://api.example.com/store/products?status=all&offset=0&limit=50";
$apiKey = 'xxxxxxx'; // apikey
$headers = array(
'Authorization: Basic '.$apiKey
);
// Send to Server
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Get response
$response = curl_exec($ch);
// Encode : decode returns string error so use encode
echo $result = json_encode($response);
With this code I get error :
"{\"code\":400,\"result\":\"Malformed Authorization header.\",\"error\":{\"reason\":\"BadRequest\",\"message\":\"Malformed Authorization header.\"}}"
I looked everywhere for solution here and here. All the answers suggest adding username and password which is not necessary with my vendor API, only Api Key and header Basic Auth. What am I doing wrong?