# Logs

Operations dealing with client, server and audit logs.

## Send client log

`POST /api/v1/server/logs/client`

Authentication: no security requirement declared for this operation.

Request body: application/json

Type: SendClientLog

Schema: [SendClientLog](https://docs.joinpeertube.org/api-rest-reference/api/models/sendclientlog.md)

- `message` (required)
  Type: string

- `url` (required)
  Type: string
  
  URL of the current user page

- `level` (required)
  Type: any
  
  enum: ["error","warn"]

- `stackTrace` (optional)
  Type: string
  
  Stack trace of the error if there is one

- `userAgent` (optional)
  Type: string
  
  User agent of the web browser that sends the message

- `meta` (optional)
  Type: string
  
  Additional information regarding this log

Responses:

- 204: successful operation

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/server/logs/client' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "message": "string",
  "url": "string",
  "level": "error",
  "stackTrace": "string",
  "userAgent": "string",
  "meta": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "message": "string",
  "url": "string",
  "level": "error",
  "stackTrace": "string",
  "userAgent": "string",
  "meta": "string"
}`;

const response = await fetch('https://peertube2.cpy.re/api/v1/server/logs/client', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "message": "string",
  "url": "string",
  "level": "error",
  "stackTrace": "string",
  "userAgent": "string",
  "meta": "string"
}'''

response = requests.post(
    'https://peertube2.cpy.re/api/v1/server/logs/client',
    data=body.encode('utf-8'),
    headers={
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Get instance logs

`GET /api/v1/server/logs`

Authentication (security requirement alternatives):

```json
[
  {
    "OAuth2": [
      "admin"
    ]
  }
]
```

- OAuth2: oauth2. Authenticating via OAuth requires the following steps:
- Have an activated account
- [Generate] an access token for that account at `/api/v1/users/token`.
- Make requests with the *Authorization: Bearer <token\>* header
- Profit, depending on the role assigned to the account

Note that the __access token is valid for 1 day__ and is given
along with a __refresh token valid for 2 weeks__.

[Generate]: https://docs.joinpeertube.org/api/rest-getting-started
; scopes: admin

Responses:

- 200: successful operation

Content type: application/json

Type: Array<string>

Items:
  Type: string

## Examples

### cURL

```bash
curl -X GET 'https://peertube2.cpy.re/api/v1/server/logs' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/server/logs', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

const data = await response.text();
```

### Python

```python
import requests

response = requests.get(
    'https://peertube2.cpy.re/api/v1/server/logs',
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```


## Get instance audit logs

`GET /api/v1/server/audit-logs`

User, administration and moderation actions recorded by all the PeerTube processes of the instance.

By default (`format=array`), returns an array of at most the 10,000 most recent entries of the requested date range, oldest first.
`startDate` is then required and pagination parameters are ignored.

With `format=list`, returns a paginated list.


Authentication (security requirement alternatives):

```json
[
  {
    "OAuth2": [
      "admin"
    ]
  }
]
```

- OAuth2: oauth2. Authenticating via OAuth requires the following steps:
- Have an activated account
- [Generate] an access token for that account at `/api/v1/users/token`.
- Make requests with the *Authorization: Bearer <token\>* header
- Profit, depending on the role assigned to the account

Note that the __access token is valid for 1 day__ and is given
along with a __refresh token valid for 2 weeks__.

[Generate]: https://docs.joinpeertube.org/api/rest-getting-started
; scopes: admin

Parameters:

- `format` (query, string, optional)
  Type: string
  
  default: "array"
  
  enum: ["array","list"]

- `start` (query, integer, optional) - Offset used to paginate results
  Type: integer
  
  minimum: 0

- `count` (query, integer, optional) - Number of items to return
  Type: integer
  
  default: 15
  
  minimum: 1
  
  maximum: 100

- `sort` (query, string, optional)
  Type: string
  
  enum: ["-createdAt","createdAt"]

- `search` (query, string, optional) - Search in usernames, IP addresses and audited entities
  Type: string

- `entityType` (query, AuditLogEntityType, optional)
  Type: AuditLogEntityType
  
  Schema: [AuditLogEntityType](https://docs.joinpeertube.org/api-rest-reference/api/models/auditlogentitytype.md)
  
  enum: ["video","video-import","video-live","video-source","video-file","video-caption","video-chapters","video-password","video-embed-privacy","video-transcoding","video-transcription","video-studio-edition","video-player-settings","ownership-change","comment","channel","channel-sync","channel-videos-import","channel-collaborator","channel-player-settings","channel-playlists-order","playlist","playlist-element","playlist-elements-order","user","registration","password-reset","token-session","failed-login","scoped-token","user-export","user-import","abuse","abuse-message","video-block","account-block","server-block","blocklist-subscription","watched-words-list","watched-words-subscription","automatic-tag-policy","config","instance-image","instance-homepage","instance-host","plugin","follow","server-redundancy","video-redundancy","job-queue","job","runner","runner-registration-token","debug-command","storage-prune"]

- `entityId` (query, integer, optional)
  Type: integer

- `action` (query, AuditLogAction, optional)
  Type: AuditLogAction
  
  Schema: [AuditLogAction](https://docs.joinpeertube.org/api-rest-reference/api/models/auditlogaction.md)
  
  enum: ["create","update","delete"]

- `startDate` (query, string, date-time, optional) - Required with the default `array` format
  Type: string, date-time

- `endDate` (query, string, date-time, optional)
  Type: string, date-time

Responses:

- 200: successful operation

Content type: application/json

Type: Array<AuditLog> | object

oneOf:
  Type: Array<AuditLog>
  
  Default `array` format
  
  Items:
    Reference: [AuditLog](https://docs.joinpeertube.org/api-rest-reference/api/models/auditlog.md); Type: AuditLog

  Type: object
  
  `list` format
  
  - `total` (optional)
    Type: integer
    
    Example:
    
    ```json
    1
    ```
  
  - `data` (optional)
    Type: Array<AuditLog>
    
    Items:
      Reference: [AuditLog](https://docs.joinpeertube.org/api-rest-reference/api/models/auditlog.md); Type: AuditLog

- 403: audit log is disabled

## Examples

### cURL

```bash
curl -X GET 'https://peertube2.cpy.re/api/v1/server/audit-logs?format=array&count=15' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/server/audit-logs?format=array&count=15', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
  },
});

const data = await response.text();
```

### Python

```python
import requests

response = requests.get(
    'https://peertube2.cpy.re/api/v1/server/audit-logs?format=array&count=15',
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```
