I'm trying to make Rest api request, but I'm not being able to get the server response.
<?php
$service_url = 'https://myservice/url';
$curl = curl_init($service_url);
$login = "username";
$token = "generated_token";
$key = time();
$md5 = md5($login . $token . $key);
$curl_post_data = array(
'login' => $login,
'key' => $key,
'md5' => $md5 ,
'action' => 'method_called',
'info_type' => 'information_needed',
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during execution. : ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
}
echo 'response ok!';
var_export($decoded->response); ?>
I'm getting response ok but I also get a php notice Notice: Trying to get property of non-object in /opt/lampp/htdocs/testApi/myfile.php on line 33 NULL
What I'm missing to retrieve the content of the response?