我请求使用时钟化API()的用户输入一些时间条目。出于某种原因,我收到了一些答复,其中包括没有结束时间的参赛作品.我注意到,意外返回的条目属于当前运行时项.但是,我没有指定/使用‘进行中’参数.这里发生了什么事?
这里是我的代码:
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():
这里是一个意外的"end“值的示例:
{
'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'
}
我只是期待时间条目已经完成。有什么建议吗?
发布于 2019-08-22 18:27:36
更新(10/16/19):
又一次跟进。他们给我发了封电子邮件说他们解决了问题。将参数“进行中”放入false将只返回已完成的时间条目。@matthew-e-miller如果能把这句话加到答案里就好了。-5小时前的Lukas Belck
好吧,所以我终于有机会重现这个问题了,看起来.没有终结时间过滤器。他们错误地提供了一个启动和结束参数,,但这两个过滤器在启动时间。
开始和结束参数的工作方式如下:
正在进行的工作与文档中描述的一样,但它不适用于您的应用程序。
答案:
我认为最好的方法是请求所有时间的条目,将它们放入一个dict/list中,然后使用python脚本删除带有“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)
输出:
列表中只包含没有timeInterval.end == 'None‘的条目。
这里是用于这个答案-编辑:的时间
https://stackoverflow.com/questions/57618989
复制相似问题