Skip to content

Instantly share code, notes, and snippets.

@chucktrukk
Created December 7, 2011 16:19
Show Gist options
  • Save chucktrukk/1443415 to your computer and use it in GitHub Desktop.
Save chucktrukk/1443415 to your computer and use it in GitHub Desktop.
toggle api example
<?php
/*
curl -v -u API_TOKEN_HERE:api_token -X GET https://www.toggl.com/api/v6/me.json
curl -v -u API_TOKEN_HERE:api_token -X GET https://www.toggl.com/api/v6/time_entries.json
curl -v -u API_TOKEN_HERE:api_token -X GET "https://www.toggl.com/api/v6/time_entries.json?start_date=2010-02-05T15%3A42%3A46%2B02%3A00&end_date=2010-02-12T15%3A42%3A46%2B02%3A00"
*/
$from_date = isset($_GET['from_date']) ? $_GET['from_date'] : date('m-d-Y');
$to_date = isset($_GET['to_date']) ? $_GET['to_date'] : date('m-d-Y');
//Set to 0:0:00 of next day for strtotime
$to_date = strtotime('+1 day', $to_date);
$from_date = date('c', strtotime($from_date));
$to_date = date('c', strtotime($to_date));
$url = "https://www.toggl.com/api/v6/time_entries.json?start_date={$from_date}&end_date{$to_date}";
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl);
curl_close($curl);
$json_result = json_decode($buffer, true);
echo '<pre>';
print_r($json_result);
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment