I have an endpoint and API key that I am testing in Postman and I get a response with data. So, setting in Postman is working as it should and my curl response in my PHP code is returning false on dumping curl response and code 200 when triggering API call.
I just implemented an endpoint and API key from my postman headers that I set. I need two parameters: int and customerNumber. In postman, they are set as raw JSON data.
Can someone figure out what am I doing wrong?
public function call($action, $parameter)
{
$endpoint = 'https://api.myendpoint.co.uk/full-dinner-serve/la/la/land';
$apiKey = 'NNOsndosfl14FS45ddgdg1';
$ch = curl_init();
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'x-api-key: ' . $apiKey;
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
$postBody = array (
'action' => $action,
'customerNumber' => $parameter
);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postBody));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
return json_decode($response, true);
}
And then calling it:
public function validate($customerNumber)
{
$response = $this->call(
'init',
$customerNumber
);
return $response;
}
And in final endpoint:
$response = $this->get('service')->validate(
$this->data['customer_number']
);