taylorhickem / tg-hours

time tracking using Toggl Track data
GNU General Public License v3.0
0 stars 0 forks source link

Toggl API bulk delete #17

Open taylorhickem opened 9 months ago

taylorhickem commented 9 months ago

bulk delete

In case of large data stored on server >100k entries, concern is that this may slow down API performance. So would like to be able to bulk delete and purge past entries older than x years. However, the API seems only to have feature to delete one entry at a time.

16

request to Toggl API support team

Hi! Do you mind if I submit a few technical clarification questions that is related to my use case? I was able to find the correct API routes for the time_entries get as well as delete, however I was unsuccessful at finding any bulk delete routes and could only find delete for a single entry at a time. So I used a for loop and it worked, however, I do have some clarification questions.

  1. If I loop the delete request for a large number of entries >> 100, will I encounter any limitations such as API rate limiting, etc.. especially if I use asynchronous requests?
  2. What is the recommended practice for bulk delete operations?
  3. Can I expect to experience any degraded API performance if I store a large number of entries (ex 7 years or ~100k entries) without purging periodically?
taylorhickem commented 9 months ago

from toggl support: diane.thompson@toggl.com

The safe bet is indeed 1 req/sec, but the user may be able to pass that limit depending on the load. There's some details on our API docs here.

Indeed the DELETE endpoint does allow only single operations. However, you can use the PATCH operation to do a bulk delete. The trick is to set the op to replace and path to /deleted_at.

Example:

PATCH https://track.toggl.com/api/v9/workspaces/9999/time_entries/1111,2222,3333 [ { "op": "add", "path": "/deleted_at" } ] This would cause the TEs 1111, 2222 and 3333 (of workspace 9999) to get deleted. If you want to undo the deletion, all you need to do is change the op to remove. There is a hard limit of 100 IDs per request