Get your own customer support community
 

How to use PHP to access the API to login, and get all entries for one day.

Can you please provide documentation on how to use PHP with Toggl? I know a lot of API's out there have examples of sample source code to show how to make it work.

Here's what I currently have:
<?php // This will be where we test the api to Toggl
$send_data = array();
$send_data['start_date_ms'] = strtotime(date("m/d/Y 00:00:00")) * 1000;
$send_data['end_date_ms'] = strtotime(date("m/d/Y 23:59:59")) * 1000;
$send_data['version'] = '0.16.12';
$send_data['tzoffset'] = '0';
$send_data['user_login'] = '{myloginaccount}';
$send_data['user_password'] = '{myloginpassword}';

$login = curl_init();
curl_setopt($login, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($login, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($login, CURLOPT_URL, 'http://www.toggl.com/user/login');
curl_setopt($login, CURLOPT_POSTFIELDS, json_encode($send_data));
$login_details = json_decode(curl_exec($login));

echo "Login Details <br ?>";
echo "<pre>";
print_r($login_details);
echo "</pre>";

$get_details = curl_init();
curl_setopt($get_details, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($get_details, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($get_details, CURLOPT_URL, 'http://www.toggl.com/task/list');
curl_setopt($get_details, CURLOPT_POSTFIELDS, json_encode($send_data));
$list_details = json_decode(curl_exec($get_details));

echo "List Details<br />";
echo "<pre>";
print_r($list_details);
echo "</pre>";

curl_close($login);
curl_close($get_details);
?>

Dump of $send_data.
Array
(
[start_date_ms] => 1240372800000
[end_date_ms] => 1240459199000
[version] => 0.16.12
[tzoffset] => 0
[user_login] => {myloginaccount}
[user_password] => {myloginpassword}
)

The login looks great, the tasks list doesn't work at all.

Thanks,
Chad

EDIT: some of the items above are not displaying on this site correctly.
 
sad I’m really sad because I can't get this to work
Inappropriate?
1 person has this question

The company marked this question as answered.


User_default_medium