Clockify API to get total number of entries for a user?

961 views Asked by At

I used Clockify to track roughly every minute of my day for the last 3 months as an experiment. I'm in the process of pulling all of my time entry data from the API so that I can analyze it and make visualizations.

I'd like to avoid getting all of the time entries at once, so I'm writing my code so it respects the default number of entries, then trying to paginate through it. I calculate the total number of pages by taking the entry count I see in the Clockify UI and dividing that by the default number of entries per page.

The Python code for this part looks like this:

num_pages = HARDCODED_VALUE
for pagenum in range(1, num_pages + 1):
    newurl = url + '?page={}'.format(pagenum)
    r = requests.get(newurl, headers=x_api_header)
    // do stuff (save to file, r.json(), etc.)

Though my use case is very specific, and an individual doing this would seemingly follow a similar procedure, I wanted to know if there is a more programmatic way of counting the total number of entries for a given user in a specific workspace? I couldn't find a feature like this, or something akin to pagination indicators, in the response from the Clockify API.

1

There are 1 answers

1
Adam DS On BEST ANSWER

This is a little late, but to get a count of records for a user, you could use the Summary report endpoint as this includes an entriesCount field which sums all records for your query regardless of the page limits. You could set the startRangeStart parameter to the date you started your account and dateRangeEnd parameter for the current day. Finally, you could filter for the specific user id.

The query: https://reports.api.clockify.me/v1/workspaces/xxxxxxx/reports/summary

The POST body:

{
  "dateRangeStart": "2010-01-01T00:00:00.000Z",
  "dateRangeEnd": "2020-12-17T23:59:59.000Z",
  "summaryFilter": {"groups": ["USER","TIMEENTRY"]},
  "exportType": "JSON",
  "users": {
    "ids": ["xxxxxxxxxx"],
     "contains": "CONTAINS",
    "status": "ALL"
  }
}

The groupings in the summaryFilter of "TIMEENTRY" will return each individual time entry, but that shouldn't matter if you just use the entriesCount field for your pagination purposes in conjunction with your original query.