Reputation: 1
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.
Upvotes: 0
Views: 459
Reputation: 1
from what I see there are couple of things fundamentally wrong with your code, starting with the headers. You never specify the type of the request being sent.
If you look at the documentation you'll see that the request for getting the report is actually a POST request with a body, without any parameters. So, to begin with, specify type of the request, add a valid body, remove the parameters and then see how it goes from there. Open a detailed report using a desired date range on the clockify app and maybe see how the request looks like. Ignore the parameters in the URL, as they are not being sent to the server, which you'll see in the network tab. The app behaves differently, and generates reports asynchronously, but the initial request remains the same.
Cheers.
Upvotes: 0