-2

this code is only returning the current day chats. not all from the 1st january 2015. What should i do now to get all chats from the given date.

$url = "https://api.livechatinc.com/chats?\date_from=2015-01-01";
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);

$result = curl_exec($curl);
echo $result;
Abdullah Khan
  • 27
  • 1
  • 6
  • I have no idea how this api works (not saw its docs, and anything) but this backslash `chats?\date_from` looks very suspicious to me – hlscalon Dec 31 '15 at 13:23

1 Answers1

3

Please have a look at this code:

<?php

$url = "https://api.livechatinc.com/chats?date_from=2015-01-01";
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-API-Version: 2'));    

$result = curl_exec($curl);
$result = json_decode($result);

print_r($result);

This is a correct request for our API, it retrieves chats all the way up form 2015-01-01. The chats are sorted from the latest to the oldest which means the oldest chats are to be found on the last page.

Please make sure you use API v2, we strongly recommend it: https://developers.livechatinc.com/rest-api/.

We will introduce sort_order parameter in 2 weeks time. We also provide and recommend our own library on github. It has all the possible api requests available.

Cheers, Adam

scana
  • 2,785
  • 2
  • 25
  • 49
  • It's only retrieving the current date chats. Not all the chats from 1st january 2015 – Abdullah Khan Jan 18 '16 at 08:46
  • Try adding the `page` parameter with last page number, for instance [link](https://api.livechatinc.com/chats?date_from=2015-01-01&page=20) where 20 is the last page. Whenever you request chats api it returns the number of chats and number of pages [link](http://take.ms/HNYrz). You can find more in our documentation [link](https://developers.livechatinc.com/rest-api/#!archives). Cheers Adam – LiveChatAdam Jan 18 '16 at 18:53
  • @LiveChatAdam This will retrieve data by paging, is there any way to list out all the chat on the single page? – Keyur Mistry May 10 '17 at 06:59