Hello!
Would like to know, what is the correct manner to update a tag in a time entry.
Today I have a script that can get actual time entry, add a tag value and use the same resource to try update tag.
My code:
def add_tag_to_time_entry(api_key, workspace_id, time_entry_id, tag_id):
# Endpoint da API
url = f"https://api.clockify.me/api/v1/workspaces/{workspace_id}/time-entries/{time_entry_id}"
# Cabeçalho com a chave de API
headers = {
"X-Api-Key": api_key,
"Content-Type": "application/json"
}
# Primeiro, obtém os detalhes atuais da entrada de tempo
response = requests.get(url, headers=headers)
time_entry = response.json()
# Adiciona o ID da tag
if "tagIds" not in time_entry:
time_entry["tagIds"] = []
time_entry["tagIds"].append(tag_id)
# Atualiza a entrada de tempo
resposta = requests.put(url, headers=headers, json=time_entry)
print(resposta.json())
But when a try this, the following error message is displayed:
{‘message’: ‘You entered invalid value for field : [start]. Values that represent [start] can't be null and can't be empty. Please make sure that the [start] date is not greater than 9999-12-31 and not less than 0001-01-01. Ensure that the [start] date is in following format: “yyyy-MM-ddThh:mm:ssZ” Example: 2018-11-29T13:00:46Z.’, ‘code’: 501}
What is wrong? My start field is exactlly how I extracted it from the api.