I am trying to implement the Engagement History API from LivePerson (https://developers.liveperson.com/engagement-history-api-methods.html) in PHP by using cURL.
It is working fine on Postman, but I cannot get it to work in PHP.
Here is my code which is part of a function inside a class:
$nonce = sha1(time());
$timestamp = time();
$oauth = new OAuth($this->consumerKey, $this->consumerSecret, OAUTH_SIG_METHOD_HMACSHA1);
$oauth->setVersion('1.0');
$oauth->setToken($this->accessToken, $this->tokenSecret);
$oauth->setTimestamp($timestamp);
$oauth->setNonce($nonce);
//Sets the HTTP Headers for the curl.
$headers = array(
'Content-Type: application/json',
'Connection: keep-alive',
'Keep-Alive: 800000',
'Authorization: ' . $oauth->getRequestHeader('POST', $url)
);
$live_person_post_data = array(
"start" => array(
"from" => 1604174400000,
"to" => 1604188740000
)
);
$live_person_post_data_Encoded = json_encode($live_person_post_data);
// Configure curl options in order to retrieve conversations from Live Person.
$opts = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $live_person_post_data_Encoded,
CURLOPT_HTTPHEADER => $headers
);
// Initialize curl
$curl = curl_init();
// Set curl options
curl_setopt_array($curl, $opts);
// Get the results
$result = curl_exec($curl);
// Close resource
curl_close($curl);
I have tried various things and all the examples I have seen are more or less the same with what I wrote above, but I keep getting {"code":"0005"} in the response.
Any help/suggestions are much appreciated.
Thank you.