Skip to content

Instantly share code, notes, and snippets.

@KevinBatdorf
Last active March 28, 2020 14:57
Show Gist options
  • Select an option

  • Save KevinBatdorf/4e34a88f6d3663c974619f6ddac4cac8 to your computer and use it in GitHub Desktop.

Select an option

Save KevinBatdorf/4e34a88f6d3663c974619f6ddac4cac8 to your computer and use it in GitHub Desktop.
This will show your tasks for a particular workspace since Monday
<?php
$key = YOUR_API_KEY;
$workspace = '2385201'; // Your team workspace
$curl = curl_init();
if (!$curl) {
die("Couldn't initialize a cURL handle");
}
// Set the file URL to fetch through cURL
$monday = date('c', strtotime('last monday'));
$now = date('c', strtotime("now"));
$query = http_build_query(['start_date' => $monday, 'end_date' => $now]);
curl_setopt($curl, CURLOPT_URL, "https://www.toggl.com/api/v8/time_entries?{$query}");
// Set a password
curl_setopt($curl, CURLOPT_USERPWD, $key . ":api_token");
// Set a different user agent string (Googlebot)
curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
// Follow redirects, if any
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
// Fail the cURL request if response code = 400 (like 404 errors)
curl_setopt($curl, CURLOPT_FAILONERROR, true);
// Return the actual result of the curl result instead of success code
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Wait for 10 seconds to connect, set 0 to wait indefinitely
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
// Execute the cURL request for a maximum of 50 seconds
curl_setopt($curl, CURLOPT_TIMEOUT, 50);
// Do not check the SSL certificates
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
// Fetch the URL and save the content
$response = curl_exec($curl);
// Check if any error has occurred
if (curl_errno($curl)) {
echo 'cURL error: ' . curl_error($curl);
} else {
echo '*Weekly Report*<br>';
$entries = [];
foreach(json_decode($response) as $entry) {
if ($entry->wid == $workspace && !in_array($entry->description, $entries))
array_push($entries, $entry->description);
}
echo '- ' . implode('<br>- ', $entries);
}
// close cURL resource to free up system resources
curl_close($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment