# List the trash of a vault

`GET /api/v1/vaults/{vault}/trash` and `QUERY /api/v1/vaults/{vault}/trash`

List what was deleted from a vault and still waits in its trash, the most recently deleted first.

Without a kind, an item deleted with a person or a group still in the trash is left out, since it comes back with them. With a kind, every item of that kind is listed.

A kind that is not available to the account, such as groups while they are not, lists nothing.

This endpoint answers GET and QUERY alike, and both return the same answer. GET sends the parameters in the address, QUERY in the request body. [How QUERY works](https://people.hansyeoh.com/docs/api/query-method).

## Parameters

- `vault` (string, required): The vault the trash belongs to, named either by the readable name it reports as slug or by its id.
- `kind` (string, optional): Only the items of one kind: contact, entity, group, relationship, life-event, reminder, group-membership, group-note or group-file. Anything else answers 422 on kind.
- `page` (integer, optional, defaults to 1): Which page to answer with.
- `per_page` (integer, optional, defaults to 25): How many items one page holds, between 1 and 100. A number outside the range is brought back into it rather than refused.

## Returns

A page of trash items, and how many there are in all. A vault of another account answers 404.

- `data` (array): The items on this page. An empty list rather than an error when there are none.
- `data[]` (object): One item.
- `data[].type` (string): Always trash_item. It names the kind of record, so a caller holding several kinds can tell them apart without looking at where they came from.
- `data[].id` (string): The id of this record, as a string even when it reads as a number. It is what every endpoint naming this record takes.
- `data[].attributes` (object): Everything the record holds.
- `data[].attributes.kind` (string): What the item is: contact, entity, group, relationship, life-event, reminder, group-membership, group-note or group-file.
- `data[].attributes.title` (string): What the item is called.
- `data[].attributes.type_label` (string): The word naming its kind, in the language of the key. A record says the name of its own type, such as Animal.
- `data[].attributes.context` (string): Where it belonged, in a few words, or null.
- `data[].attributes.deleted_at` (timestamp): When it was deleted, as a count of seconds since 1970.
- `data[].attributes.deleted_for_good_at` (timestamp): When it is deleted for good unless restored before, as a count of seconds since 1970.
- `data[].attributes.deleted_with` (object): The person or the group it was deleted with, while that one is still in the trash. Null otherwise.
- `data[].attributes.deleted_with.kind` (string): contact or group.
- `data[].attributes.deleted_with.id` (uuid): The id of the person or the group, which addresses it in the trash.
- `data[].attributes.deleted_with.title` (string): Their name.
- `data[].attributes.can_be_restored` (boolean): Whether restoring it now would work.
- `data[].attributes.obstacle` (string): Why it cannot be restored yet, or null when it can.
- `meta` (object): Where you are in the collection.
- `meta.page` (integer): The page this is, counting from 1.
- `meta.per_page` (integer): How many one page holds, which is the size that was asked for once it has been brought into the allowed range.
- `meta.total` (integer): How many items there are in all, not how many are on this page.

## Status codes

| Code | When | Body |
| --- | --- | --- |
| `422` Unprocessable Content | With QUERY, a parameter was sent both in the address and in the body. | A message, and an errors object naming each parameter sent twice. |

## Rate limit

Sixty requests per minute, per user, shared by every key and device. Every answer carries the budget left in `X-RateLimit-Remaining`.

## Request

```sh
curl https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/trash?kind=life-event?kind=life-event&page=1&per_page=25 \
  -H "Authorization: Bearer $MONICA_TOKEN"
```

```javascript
const response = await fetch('https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/trash?kind=life-event?kind=life-event&page=1&per_page=25', {
  headers: { Authorization: `Bearer ${token}` },
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->get('https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/trash?kind=life-event?kind=life-event&page=1&per_page=25');
```

## Request with QUERY

```sh
curl https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/trash?kind=life-event \
  -X QUERY \
  -H "Authorization: Bearer $MONICA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
      "kind": "life-event",
      "page": 1,
      "per_page": 25
  }'
```

```javascript
const response = await fetch('https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/trash?kind=life-event', {
  method: 'QUERY',
  headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    kind: 'life-event',
    page: 1,
    per_page: 25,
  }),
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->query('https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/trash?kind=life-event', [
    'kind' => 'life-event',
    'page' => 1,
    'per_page' => 25,
]);
```

## Response

`200`

```json
{
    "data": [
        {
            "type": "trash_item",
            "id": "e4a71b2c-9d36-4f85-b0c3-61a8d2f7e940",
            "attributes": {
                "kind": "life-event",
                "title": "Opened Serenity by Jan",
                "type_label": "Life event",
                "context": "About Jan Levinson",
                "deleted_at": 1795600800,
                "deleted_for_good_at": 1798192800,
                "deleted_with": {
                    "kind": "contact",
                    "id": "7c2e9a41-5b8d-4f63-a1e0-3d94b6f2c815",
                    "title": "Jan Levinson"
                },
                "can_be_restored": false,
                "obstacle": "Deleted with Jan Levinson. Restore Jan Levinson to bring this back."
            }
        }
    ],
    "meta": {
        "page": 1,
        "per_page": 25,
        "total": 1
    }
}
```
