# List the files of a group

`GET /api/v1/vaults/{vault}/groups/{group}/files` and `QUERY /api/v1/vaults/{vault}/groups/{group}/files`

List the files kept with a group, the newest first.

Files kept with a group need both groups and file upload to be available to your account. Until they are, every endpoint here answers 404.

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 group lives in, named either by the readable name it reports as slug or by its id.
- `group` (uuid, required): The id of the group. One addressed through the wrong vault, deleted, or belonging to another account, answers 404.
- `page` (integer, optional, defaults to 1): Which page to answer with.
- `per_page` (integer, optional, defaults to 25): How many records one page holds, between 1 and 100. A number outside the range is brought back into it rather than refused.

## Returns

A page of group file objects, and how many there are in all. A group belonging to somebody else answers 404.

- `data` (array): The files on this page. An empty list rather than an error when there are none.
- `data[]` (object): One file.
- `data[].type` (string): Always group_file. 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.group` (object): The group the file is kept with.
- `data[].attributes.group.id` (uuid): The id of the group.
- `data[].attributes.group.name` (string): What the group is called.
- `data[].attributes.name` (string): The name the file had when it was uploaded.
- `data[].attributes.mime_type` (string): The type of the file, such as application/pdf.
- `data[].attributes.size_in_bytes` (integer): How large the file is, in bytes. It counts against the storage of the account.
- `data[].attributes.created_at` (timestamp): When the file was kept with the group, as a count of seconds since 1970.
- `data[].links` (object): Where to find this record.
- `data[].links.self` (string): The absolute address this record is read from.
- `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 files there are in all, not how many are on this page.
- `data[].links.content` (string): The absolute address the file itself is downloaded from.

## 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/groups/5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7/files?page=2&per_page=10 \
  -H "Authorization: Bearer $MONICA_TOKEN"
```

```javascript
const response = await fetch('https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/groups/5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7/files?page=2&per_page=10', {
  headers: { Authorization: `Bearer ${token}` },
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->get('https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/groups/5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7/files?page=2&per_page=10');
```

## Request with QUERY

```sh
curl https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/groups/5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7/files \
  -X QUERY \
  -H "Authorization: Bearer $MONICA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
      "page": 2,
      "per_page": 10
  }'
```

```javascript
const response = await fetch('https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/groups/5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7/files', {
  method: 'QUERY',
  headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    page: 2,
    per_page: 10,
  }),
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->query('https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/groups/5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7/files', [
    'page' => 2,
    'per_page' => 10,
]);
```

## Response

`200`

```json
{
    "data": [
        {
            "type": "group_file",
            "id": "c4a8e1d7-6b32-4f95-8d10-2e7a93b5f6c8",
            "attributes": {
                "group": {
                    "id": "5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7",
                    "name": "Party planning committee"
                },
                "name": "office-picnic-schedule.pdf",
                "mime_type": "application/pdf",
                "size_in_bytes": 48213,
                "created_at": 1791547200
            },
            "links": {
                "self": "https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/groups/5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7/files/c4a8e1d7-6b32-4f95-8d10-2e7a93b5f6c8",
                "content": "https://people.hansyeoh.com/api/v1/vaults/dunder-mifflin/groups/5d2a7c91-3e48-4b06-9f1d-a83c60e2b4f7/files/c4a8e1d7-6b32-4f95-8d10-2e7a93b5f6c8/content"
            }
        }
    ],
    "meta": {
        "page": 1,
        "per_page": 25,
        "total": 1
    }
}
```
