> ## Documentation Index
> Fetch the complete documentation index at: https://developers.lucca.fr/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Mass Delete TimeEntries

## Introduction

**This guide is aimed at helping you mass delete TimeEntries.** It can help you reset clear TimeEntries after an
incorrect import or any problem encountered when [updating TimeEntries](./update-time-entries).

<Danger>
  **Deletion is permanent**.
  Please bear in mind that once TimeEntries have been deleted,
  they cannot be restored back.
</Danger>

## Prerequisites

You will need:

* (required) Your domain name `{yourDomain}`, eg: "[https://myawesomecompany.ilucca.net](https://myawesomecompany.ilucca.net)".
* (required) An [API key](https://support.lucca.fr/hc/en-us/articles/115000084851) `{apiKey}` that has TimeEntries editing rights to the given owners.

## Guide

### 1. Identify TimeEntries

<Warning>
  **Submitted TimeEntries cannot be deleted.**
  Once a timesheet has been submitted, and whether or not it is
  approved, the TimeEntries it contains can no longer be modified
  or deleted. You may want to first reject the timesheet, and there's
  [a guide for this](./mass-rejection-timesheets).
</Warning>

Retrieving TimeEntries is achieved through the `/api/v3/timeentries` endpoint. Its [API reference can be found here.](../../timmi-timesheet)

In order to isolate the TimeEntries that need to be deleted, the most common filters are:

* `?ownerId=1,2,...`: filter on the user(s).
* `?startsAt=between,2022-01-01,2022-O2-01`: filter on the TimeEntry date.
* `?unit=0,1,2`: filter on the TimeEntry unit.

<Warning>
  **Please page your request.**
  Requests aimed at retrieving a large set of resources should be paged.
  [You can read more about paging here](../../introduction).
</Warning>

The request should look like this:

```http theme={null}
GET /api/v3/timeentries?ownerId=416&startsAt=between,2022-01-01,2022-O2-01&paging=0,1000&fields=id,ownerId,startsAt,timesheetId,collection.count HTTP/1.1
Host: {yourDomain}
Authorization: lucca application={apiKey}
Accept: application/json

Response:
{
  "data": {
    "count": 1, 
    "items": [
      {
        "id": 12354,
        "ownerId": 416,
        "startsAt": "2021-01-01 08:45:00",
        "timesheetId": null
      }
    ]
  }
}
```

<Info>
  **If timesheetId is not null.**
  If the `timesheetId` of the returned TimeEntries is not null, then it
  belongs to a submitted timesheet and cannot be deleted as long as said
  timesheet is not rejected.
</Info>

### 2. Delete TimeEntries

Deleting TimeEntries can be done through a DELETE request on the `/api/v3/timeentries` endpoint. The array of TimeEntries to delete must be passed in the request body.

Please refer to the [API reference.](../..//timmi-timesheet)

```http theme={null}
DELETE /api/v3/timeentries HTTP/1.1
Host: {yourDomain}
Authorization: lucca application={apiKey}
Content-Type: application/json

[
  {
    "id": 12354
  }
]
```
