This Google Apps script imports time entries from Toggl.com into a Google Sheet using their Detailed Report API.
For a given month it aggregates the time entries per day and per customer.
Open this Google Sheet and make a copy in your Google Drive account.
Create a new Google Sheet.
Create a new script in your newly created Google Sheet and paste the contents of
all of the src/*.gs
files in their respective script files.
Rename the first sheet as Config.
Add the following information in cell A1 of the Config sheet:
A: Variable | B: Value | C: Description | |
---|---|---|---|
1 | timesheetDate | 01/01/2015 | Timesheet Month |
2 | workspaceId | workspaceId | Toggl Workspace Id |
3 | apiToken | your toggle api token | Toggl API Token |
To figure out your workspace_id: go to Team in toggl.com. The number at the end of the URL is the workspace id.
To figure out your api_token: go to your Profile in toggl.com, your API token is at the bottom of the page.
Re-open your Google Sheet. Now you will have a new menu called "Toggl" with a sub-menu "Get Timesheet for Month".
Fill a date of the month you want to import in cell B1. If you want your timesheet for December 2014, fill the date 01/12/2014 and click Toggl > Get Timesheet for Month.
It also calculates the number of days worked during that month.
Google App Scripts only supports EcmaScript 5 because it is powered by Mozilla's Rhina Javascript Interpreter.
toggl-google-sheet is written in ES6 (aka EcmaScript2015). But the codebase still implements classes the old way using functions. That is because of historical reasons. The codebase started in full ES5 mode as a pure hack. Gradually, it got refactored by introducing classes, the hexagonal architecture and DDD concepts.
Webpack and Babel are used to transpile ES6 to ES5.
./src/Code.js
: contains the global functions required by Google Apps Script written in ES5../src/App.js
: entry point for Webpack bundle. Here we can use ES6 modules written in ES6. The bundle is exposed as a global variableapp
toCode.js
.
Since early 2020, Google App Scripts is now supported by the V8 Runtime that powers Chrome and Node.js. But ES6 modules are not yet supported.
Because ES6 modules are not supported, there is still value in transpiling. And, the right now the Google Sheets still use the Rhino powered Google App Scripts.
To run the tests:
npm install
npm test
Tests are implemented using Jest.
To transpile the ES6 to ES5 for Google Apps Script:
npm run build
koen-github for providing an example on how to use the Toggl API with Google Sheet.
GSmart.in for providing an example of using ES6 and webpack/babel for Google Apps Script. See also Creating a complete web app on Google Apps Script using Google Sheet as database.