dsetton
dsetton

Reputation: 826

Clockify API - Restart time entry

I would like to mark the last time entry for a user as the current time entry. In other words, I would like to clear the end field of a given time entry, to indicate that it it not finished yet, it's still running.

Is it possible to do that?

I tried using the Update time entry on workspace endpoint, like so:

curl -H 'Content-Type':'application/json' \
  -H 'X-Api-Key':'API_KEY' \
  -X PUT https://api.clockify.me/api/workspaces/WORKSPACE_ID/timeEntries/TIME_ENTRY_ID \
  -d '{"end":null}'

But the response code is 400 with the following response:

{"message":"text","code":3002}

What does this error code mean?

Upvotes: 1

Views: 709

Answers (1)

Stephen Read
Stephen Read

Reputation: 26

So the documentation for the UpdateTimeEntryRequest (https://clockify.github.io/clockify_api_docs/#/definitions/UpdateTimeEntryRequest) is a bit wrong or incomplete. I figured it out through some testing, here's what you need to do:

First, you need to make sure you have the current data of the time entry, specifically the start date and billable status (as these are the only two "required" fields in the API call). You are getting the 400 bad request because you are missing these two fields - the error message is obviously no help here, but a 400 response code means "the server was unable to process the request sent by the client due to invalid syntax.", which makes sense, since your input is invalid.

Assuming you have the time entry information already (which is the only way I could see how you would know the ID), you could recreate the whole UpdateTimeEntryRequest data but then null out the end field or leave it out completely, like this:

{
  "start": START_FROM_THE_TIME_ENTRY,
  "billable": BILLABLE_FROM_THE_TIME_ENTRY,
  "description": DESC_FROM_THE_TIME_ENTRY,
  "projectId": PROJECT_ID,
  "taskId": TASK_ID,
  "end": null,
  "tagIds": TAGS_ARRAY
}

From my testing, this restarts the timer. If you leave out any field, those fields are reset, for example:

{
  "start": START_FROM_THE_TIME_ENTRY,
  "billable": BILLABLE_FROM_THE_TIME_ENTRY
}

would restart the timer, but it would clear the description, project/task, and tags, which is probably not preferable.

Upvotes: 1

Related Questions