I'm having trouble trying to get my code running. I'm trying to use cUrl with a post and http authentication but I'm unable to get it to work.
I'm using the following code:
public function index(){
$call = $this->call("URL_TO_CALL", $this->getCredentials(), $this->getJson());
}
private function getCredentials(){
return "API_KEY_HERE";
}
private function getJson(){
return $json;
}
private function call($page, $credentials, $post){
$url = "URL_TO_CALL";
$page = "/shipments";
$headers = array(
"Content-type: application/vnd.shipment+json;charset=utf-8",
"Authorization: Basic :" . base64_encode($credentials)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Apply the POST to our curl call
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$data = curl_exec($ch);
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
} else {
// Show me the result
var_dump($data);
curl_close($ch);
}
}
The response I'm getting is:
{"errors":[{"code":3001}],"message":"Permission Denied. (insertShipment)"}
I was expecting a list of shipments. Am I doing something obviously wrong here?