An API wrapper to simplify interactions with the official Toggl API.
Find out more about Toggl.
You will need your API token that you can find in your Toggl profile.
You will also likely need to get the domain that you will be making requests from whitelisted so that the API returns the correct CORS headers. You can do so by emailing [email protected] with your domain name and requesting that it be added. They usually respond within 24 hours of making the request.
You will also require jQuery, but I hope to remove this requirement as it is really only being used to make the AJAX request.
var Toggl = TogglClient(myToken);
All requests return a promise with the API response that you can then use.
var timerId;
Toggl.timers.start('My Test Timer').then(function(timer){
// Do stuff - eg. toggle the button state to stop the timer
timerId = timer.data.id;
});
Toggl.timers.stop(timerId).then(function(){
// Do stuff - eg. toggle the button state back to start another timer
});
var timerId;
Toggl.timers.current().then(function(timer){
if(timer.data !== null)
timerId = timer.data.id;
}
});
Toggl.clients.create('My Client Pty Ltd').then(function(client){
});
Toggl.clients.getProjects(clientId).then(function(projectArray){
// for(var i = 0; i < projectArray.length; i++){ ... }
});
JSToggl may be freely distributed under the GPL v2 license.