I am struggling to pull reported data in Clockify to google spreadsheet, here's the code I am trying to trigger.
function getClockifyReport() {
const headers = {
"headers": {
"X-Api-Key": "[APIKEY]",
"content-type": "application/json",
"Accept": "*/*"
}
};
const workspaceId = "WORKSPACE_ID";
const url = `https://reports.api.clockify.me/v1/workspaces/${workspaceId}/reports/detailed?userGroupIds=all&projectIds=all&clientIds=all&billable=null&invoiced=null&approved=null&sortByDate=null&sortAscending=null&page=1&pageSize=50&considerDurationFormat=null&roundingMinutes=null&formatted=false`;
const response = UrlFetchApp.fetch(url, headers);
const data = JSON.parse(response.getContentText());
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet 1");
sheet.clear();
sheet.appendRow(["Description", "Start Time", "End Time", "Duration", "User", "Client", "Project"]);
data.timeEntries.forEach((entry) => {
sheet.appendRow([
entry.description,
entry.timeInterval.start,
entry.timeInterval.end,
entry.timeInterval.duration,
entry.user.name,
entry.client.name,
entry.project.name
]);
});
}
If you'd like to test the script, open a google spreadsheet > Extensions > apps script. Clockify documentation: https://docs.clockify.me/
What am I doing wrong?
Tried adjusting the code like 100 times and spent hours of research without any luck on solving this.
I am expecting to pull all available reported data in clockify by users, and automate the reporting process in google spreadsheets.