Hello,
I’ve a problem with an API request to get cockpit collections and I don’t understand why. I’ve a simple php page where I do the request with curl to get collections (so with method ‘POST’ and I have a 403 response " Forbidden.
You don’t have permission to access this resource".
My request seems to be right (I checked all). I tried the same request with POSTMAN and there I have my entries.
So why from my application I have a 403 error ? Do I have to change something in a config file ?
Can someone help me or have an idea ?
Thank you in advance
function callAPI($method, $url, $data){
$authToken = "xxxxxxx";
$curl = curl_init();
switch ($method){
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
// OPTIONS:
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer ".$authToken,
'Content-Type: application/json'
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);
// EXECUTE:
$result = curl_exec($curl);
var_dump($result); //this return 403 error message
if(!$result){die("Connection Failure");}
curl_close($curl);
return $result;
}