1

I'm requesting some time entries for users with the Clockify API(). For some reason, I am receiving some responses which include entries without an end-time. I noticed that, the unexpectedly returned entries belong to currently running time entires... However, I did not specify/use the 'in-progress' parameter... What is happening here?

Here is my code:

def fetch_users_time_entries(users):
    API_URL = "https://api.clockify.me/api/v1"
    for user in users:
        url = "{}/workspaces/{}/user/{}/time-entries?hydrated=true&page-size=1000&start=2019-08-05T00:00:01Z".format(API_URL, WORKSPACE_ID, user['clockify_id'])
        time_entries = requests.get(url, headers=HEADER)
        for time_entry in time_entries.json():

Here is a sample of an unexpected "end" value:

{  
   'id':'SECRET',
   'description':'',
   'tags':[  
      {  
         'id':'SECRET',
         'name':'CERTI',
         'workspaceId':'SECRET'
      }
   ],
   'user':None,
   'billable':True,
   'task':{  
      'id':'SECRET',
      'name':'Etapa: Execução e Controle',
      'projectId':'SECRET',
      'assigneeId':'',
      'estimate':'PT0S',
      'status':'ACTIVE'
   },
   'project':{  
      'id':'SECRET',
      'name':'C105',
      'hourlyRate':{  
         'amount':0,
         'currency':'USD'
      },
      'clientId':'SECRET',
      'workspaceId':'SECRET',
      'billable':True,
      'memberships':[  
         {  
            'userId':'SECRET',
            'hourlyRate':None,
            'targetId':'SECRET',
            'membershipType':'PROJECT',
            'membershipStatus':'ACTIVE'
         }
      ],
      'color':'#8bc34a',
      'estimate':{  
         'estimate':'PT0S',
         'type':'AUTO'
      },
      'archived':False,
      'duration':'PT25H20M12S',
      'clientName':'NEO',
      'public':True
   },
   'timeInterval':{  
      'start':'2019-08-22T18:55:55Z',
      'end':None,
      'duration':None
   },
   'workspaceId':'SECRET',
   'totalBillable':None,
   'hourlyRate':None,
   'isLocked':False,
   'userId':'SECRET',
   'projectId':'SECRET'
}

I was only expecting time entries that were completed. Any suggestions?

Matthew E. Miller
  • 557
  • 1
  • 5
  • 13
Lukas Belck
  • 30
  • 2
  • 8

1 Answers1

1

UPDATE (10/16/19):

Another follow-up. They just send me an e-mail saying they fixed the problem. Putting the parameter "in-progress" to false will return only completed time entries. @matthew-e-miller it would be nice to add this to the answer. – Lukas Belck 5 hours ago


Okay, so I finally had a chance to reproduce the problem and it seems... There is not an end-time filter. They have misleadingly provided a start and end parameter, but these both filter on start-time.

The start and end parameters work like this:

Clockify Start and End Overview

The in-progress works as described in the doc, but it doesn't work for your application.

Answer:

I think your best bet is to request all the time entries, place them into a dict/list, and then use your python script to remove elements with "'end: 'None'".

import requests
import json

headers = {"content-type": "application/json", "X-Api-Key": "your api key""}

workspaceId = "your workspace id"
userId = "your user id"
params = {'start': '2019-08-28T11:10:32.998Z', 'end': '2019-08-29T02:05:02Z', 'in-progress': 'true'}
API_URL = "https://api.clockify.me/api/v1/workspaces/{workspaceId}/user/{userId}/time-entries"

print(API_URL)
result_one = requests.get(API_URL, headers=headers, params=params)
print(result_one)
List = json.loads(result_one.text)
for entry in List:
    if entry.get("timeInterval")['end'] == None:
      List.remove(entry)
print(List)

Output:

List containing only entries which do not have timeInterval.end == 'None'.

Here is time spent on this answer-edit:

Clockify Time Spent On Question

Matthew E. Miller
  • 557
  • 1
  • 5
  • 13
  • Even using the end-time parameter I'm still receiving time entries without end-time – Lukas Belck Aug 25 '19 at 21:22
  • Okay, I'll recreate the problem and let you know. – Matthew E. Miller Aug 25 '19 at 23:20
  • @matthwe-e-miller Did you manage to recreate the problem? I also tried setting the in-progress parameter to false, but it didn't work. If you want I can share some pictures with the requests showing the time-entry with no end-time, maybe I'm doing something wrong. – Lukas Belck Aug 28 '19 at 12:44
  • @LukasBelck I finally had a chance to recreate the problem. I edited my answer to reflect what I found about the API. I explained everything in this newly-edited answer. I hope this helps. It definitely solves your problem, so give it a check mark if you're satisfied. – Matthew E. Miller Aug 29 '19 at 04:09
  • @matthwe-e-miller thanks for the answer. I didn't know the end parameter was actually for the start-date. I was already removing the entries without end-time but wanted a clever/cleaner way to do it. – Lukas Belck Aug 30 '19 at 22:23
  • 1
    Just a follow-up. I got in contact with Clockify support and it seems that the "in-progress" parameter is not working and they are working on it. Setting the "in-progress" to false should return only time entries with end-time. – Lukas Belck Sep 04 '19 at 03:46
  • Another follow-up. They just send me an e-mail saying they fixed the problem. Putting the parameter "in-progress" to false will return only completed time entries. @matthwe-e-miller it would be nice to add this to the answer. – Lukas Belck Oct 16 '19 at 14:34
  • @LukasBelck added. – Matthew E. Miller Oct 16 '19 at 19:44