# Users

Using some features of PeerTube require authentication, for which User provide different levels of permission as well as associated user information. Each user has a corresponding local Account for federation.


## List users

`GET /api/v1/users`

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:

- `search` (query, string, optional) - Plain text search that will match with user usernames or emails
  Type: string

- `blocked` (query, boolean, optional) - Filter results down to (un)banned users
  Type: boolean

- `role` (query, UserRole, optional) - Filter results down to users with a specific role
  Type: UserRole
  
  The user role (Admin = `0`, Moderator = `1`, User = `2`)
  
  Schema: [UserRole](https://docs.joinpeertube.org/api-rest-reference/api/models/userrole.md)
  
  enum: [0,1,2]
  
  Example:
  
  ```json
  2
  ```

- `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) - Sort users by criteria
  Type: string
  
  enum: ["-id","-username","-createdAt"]

Responses:

- 200: successful operation

Content type: application/json

Type: Array<User>

Items:
  Reference: [User](https://docs.joinpeertube.org/api-rest-reference/api/models/user.md); Type: User

## Examples

### cURL

```bash
curl -X GET 'https://peertube2.cpy.re/api/v1/users?count=15' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/users?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/users?count=15',
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```


## Create a user

`POST /api/v1/users`

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

Request body: application/json (required)

If the smtp server is configured, you can leave the password empty and an email will be sent
asking the user to set it first.


Type: AddUser

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

- `username` (required)
  Reference: [username](https://docs.joinpeertube.org/api-rest-reference/api/models/username.md); Type: username
  
  immutable name of the user, used to find or mention its actor
  
  minLength: 1
  
  maxLength: 50
  
  pattern: "/^[a-z0-9._]+$/"
  
  Example:
  
  ```json
  "chocobozzz"
  ```

- `password` (required)
  Reference: [password](https://docs.joinpeertube.org/api-rest-reference/api/models/password.md); Type: password, password
  
  minLength: 6
  
  maxLength: 50

- `email` (required)
  Type: string, email
  
  The user email

- `videoQuota` (optional)
  Type: integer
  
  The user video quota in bytes
  
  Example:
  
  ```json
  -1
  ```

- `videoQuotaDaily` (optional)
  Type: integer
  
  The user daily video quota in bytes
  
  Example:
  
  ```json
  -1
  ```

- `channelName` (optional)
  Reference: [usernameChannel](https://docs.joinpeertube.org/api-rest-reference/api/models/usernamechannel.md); Type: usernameChannel
  
  immutable name of the channel, used to interact with its actor
  
  minLength: 1
  
  maxLength: 50
  
  pattern: "/^[a-zA-Z0-9\\\\-_.:]+$/"
  
  Example:
  
  ```json
  "framasoft_videos"
  ```

- `role` (required)
  Reference: [UserRole](https://docs.joinpeertube.org/api-rest-reference/api/models/userrole.md); Type: UserRole
  
  The user role (Admin = `0`, Moderator = `1`, User = `2`)
  
  enum: [0,1,2]
  
  Example:
  
  ```json
  2
  ```

- `adminFlags` (optional)
  Reference: [UserAdminFlags](https://docs.joinpeertube.org/api-rest-reference/api/models/useradminflags.md); Type: UserAdminFlags
  
  Admin flags for the user (None = `0`, Bypass video blocklist = `1`)
  
  enum: [0,1]
  
  Example:
  
  ```json
  1
  ```

- `currentPassword` (optional)
  Type: currentPassword
  
  Required to create an administrator, see [password confirmation](https://docs.joinpeertube.org/api-rest-reference/api.md#password-confirmation)
  
  allOf:
    Reference: [currentPassword](https://docs.joinpeertube.org/api-rest-reference/api/models/currentpassword.md); Type: currentPassword, password
    
    Password of the authenticated user, required if [password confirmation](https://docs.joinpeertube.org/api-rest-reference/api.md#password-confirmation) is enabled

Responses:

- 200: user created

Content type: application/json

Type: AddUserResponse

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

- `user` (optional)
  Type: object
  
  - `id` (optional)
    Reference: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md); Type: id
    
    minimum: 1
    
    Example:
    
    ```json
    42
    ```
  
  - `account` (optional)
    Type: object
    
    - `id` (optional)
      Reference: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md); Type: id
      
      minimum: 1
      
      Example:
      
      ```json
      42
      ```

- 403: insufficient authority to create an admin or moderator

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/users' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "username": "chocobozzz",
  "password": "********",
  "email": "user@example.com",
  "videoQuota": -1,
  "videoQuotaDaily": -1,
  "channelName": "framasoft_videos",
  "role": 2,
  "adminFlags": 1
}'
```

### JavaScript

```javascript
const body = `{
  "username": "chocobozzz",
  "password": "********",
  "email": "user@example.com",
  "videoQuota": -1,
  "videoQuotaDaily": -1,
  "channelName": "framasoft_videos",
  "role": 2,
  "adminFlags": 1
}`;

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

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

### Python

```python
import requests

body = '''{
  "username": "chocobozzz",
  "password": "********",
  "email": "user@example.com",
  "videoQuota": -1,
  "videoQuotaDaily": -1,
  "channelName": "framasoft_videos",
  "role": 2,
  "adminFlags": 1
}'''

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


## Get a user

`GET /api/v1/users/{id}`

Authentication (security requirement alternatives):

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

- 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


Parameters:

- `id` (path, id, required) - Entity id
  Type: id
  
  Schema: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md)
  
  minimum: 1
  
  Example:
  
  ```json
  42
  ```

- `withStats` (query, boolean, optional) - include statistics about the user (only available as a moderator/admin)
  Type: boolean

Responses:

- 200: As an admin/moderator, you can request a response augmented with statistics about the user's
moderation relations and videos usage, by using the `withStats` parameter.


Content type: application/json

Type: User | User & any

oneOf:
  Reference: [User](https://docs.joinpeertube.org/api-rest-reference/api/models/user.md); Type: User

  Reference: [UserWithStats](https://docs.joinpeertube.org/api-rest-reference/api/models/userwithstats.md); Type: User & any

## Examples

### cURL

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

### JavaScript

```javascript
const response = await fetch('https://peertube2.cpy.re/api/v1/users/42', {
  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/users/42',
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```


## Update a user

`PUT /api/v1/users/{id}`

Authentication (security requirement alternatives):

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

- 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


Parameters:

- `id` (path, id, required) - Entity id
  Type: id
  
  Schema: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md)
  
  minimum: 1
  
  Example:
  
  ```json
  42
  ```

Request body: application/json (required)

Type: UpdateUser

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

- `email` (optional)
  Type: email
  
  The updated email of the user
  
  allOf:
    Type: email, email
    
    The user email

- `emailVerified` (optional)
  Type: boolean
  
  Set the email as verified

- `videoQuota` (optional)
  Type: integer
  
  The updated video quota of the user in bytes

- `videoQuotaDaily` (optional)
  Type: integer
  
  The updated daily video quota of the user in bytes

- `pluginAuth` (optional)
  Type: string; nullable
  
  The auth plugin to use to authenticate the user
  
  Example:
  
  ```json
  "peertube-plugin-auth-saml2"
  ```

- `role` (optional)
  Reference: [UserRole](https://docs.joinpeertube.org/api-rest-reference/api/models/userrole.md); Type: UserRole
  
  The user role (Admin = `0`, Moderator = `1`, User = `2`)
  
  enum: [0,1,2]
  
  Example:
  
  ```json
  2
  ```

- `adminFlags` (optional)
  Reference: [UserAdminFlags](https://docs.joinpeertube.org/api-rest-reference/api/models/useradminflags.md); Type: UserAdminFlags
  
  Admin flags for the user (None = `0`, Bypass video blocklist = `1`)
  
  enum: [0,1]
  
  Example:
  
  ```json
  1
  ```

- `password` (optional)
  Reference: [password](https://docs.joinpeertube.org/api-rest-reference/api/models/password.md); Type: password, password
  
  minLength: 6
  
  maxLength: 50

- `currentPassword` (optional)
  Type: currentPassword
  
  Required to give the administrator role, or to change the password, email or auth plugin of an administrator, see [password confirmation](https://docs.joinpeertube.org/api-rest-reference/api.md#password-confirmation)
  
  
  allOf:
    Reference: [currentPassword](https://docs.joinpeertube.org/api-rest-reference/api/models/currentpassword.md); Type: currentPassword, password
    
    Password of the authenticated user, required if [password confirmation](https://docs.joinpeertube.org/api-rest-reference/api.md#password-confirmation) is enabled

Responses:

- 204: successful operation

## Examples

### cURL

```bash
curl -X PUT 'https://peertube2.cpy.re/api/v1/users/42' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "emailVerified": true,
  "videoQuota": 0,
  "videoQuotaDaily": 0,
  "pluginAuth": "peertube-plugin-auth-saml2",
  "role": 2,
  "adminFlags": 1,
  "password": "********"
}'
```

### JavaScript

```javascript
const body = `{
  "emailVerified": true,
  "videoQuota": 0,
  "videoQuotaDaily": 0,
  "pluginAuth": "peertube-plugin-auth-saml2",
  "role": 2,
  "adminFlags": 1,
  "password": "********"
}`;

const response = await fetch('https://peertube2.cpy.re/api/v1/users/42', {
  method: 'PUT',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "emailVerified": true,
  "videoQuota": 0,
  "videoQuotaDaily": 0,
  "pluginAuth": "peertube-plugin-auth-saml2",
  "role": 2,
  "adminFlags": 1,
  "password": "********"
}'''

response = requests.put(
    'https://peertube2.cpy.re/api/v1/users/42',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Delete a user

`DELETE /api/v1/users/{id}`

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:

- `id` (path, id, required) - Entity id
  Type: id
  
  Schema: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md)
  
  minimum: 1
  
  Example:
  
  ```json
  42
  ```

Responses:

- 204: successful operation

## Examples

### cURL

```bash
curl -X DELETE 'https://peertube2.cpy.re/api/v1/users/42' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

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

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

### Python

```python
import requests

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


## Block a user

`POST /api/v1/users/{id}/block`

Prevent a user from logging in and interacting with the instance

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:

- `id` (path, id, required) - Entity id
  Type: id
  
  Schema: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md)
  
  minimum: 1
  
  Example:
  
  ```json
  42
  ```

Request body: application/json

Type: object

- `reason` (optional)
  Type: string
  
  Optional reason for blocking the user
  
  minLength: 0
  
  maxLength: 500

Responses:

- 204: successful operation

- 400: invalid user id

- 403: insufficient permissions to block users

- 404: user not found

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/users/42/block' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "reason": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "reason": "string"
}`;

const response = await fetch('https://peertube2.cpy.re/api/v1/users/42/block', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "reason": "string"
}'''

response = requests.post(
    'https://peertube2.cpy.re/api/v1/users/42/block',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Unblock a user

`POST /api/v1/users/{id}/unblock`

Allow a previously blocked user to login and interact with the instance

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:

- `id` (path, id, required) - Entity id
  Type: id
  
  Schema: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md)
  
  minimum: 1
  
  Example:
  
  ```json
  42
  ```

Responses:

- 204: successful operation

- 400: invalid user id

- 403: insufficient permissions to unblock users

- 404: user not found

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/users/42/unblock' \
  -H 'Authorization: Bearer YOUR_TOKEN'
```

### JavaScript

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

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

### Python

```python
import requests

response = requests.post(
    'https://peertube2.cpy.re/api/v1/users/42/unblock',
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
    },
)
print(response.text)
```


## Ask to reset password

`POST /api/v1/users/ask-reset-password`

An email containing a reset password link

Authentication: no security requirement declared for this operation.

Request body: application/json

Type: object

- `email` (required)
  Type: string
  
  User email

Responses:

- 204: successful operation

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/users/ask-reset-password' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "email": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "email": "string"
}`;

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

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

### Python

```python
import requests

body = '''{
  "email": "string"
}'''

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


## Reset password

`POST /api/v1/users/{id}/reset-password`

Authentication: no security requirement declared for this operation.

Parameters:

- `id` (path, id, required) - Entity id
  Type: id
  
  Schema: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md)
  
  minimum: 1
  
  Example:
  
  ```json
  42
  ```

Request body: application/json

Type: object

- `verificationString` (required)
  Type: string, url

- `password` (required)
  Type: string

Responses:

- 204: successful operation

- 403: invalid verification string

- 404: user not found

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/users/42/reset-password' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "verificationString": "https://example.com",
  "password": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "verificationString": "https://example.com",
  "password": "string"
}`;

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

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

### Python

```python
import requests

body = '''{
  "verificationString": "https://example.com",
  "password": "string"
}'''

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


## Request two factor auth

`POST /api/v1/users/{id}/two-factor/request`

Request two factor authentication for a user

Authentication (security requirement alternatives):

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

- 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


Parameters:

- `id` (path, id, required) - Entity id
  Type: id
  
  Schema: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md)
  
  minimum: 1
  
  Example:
  
  ```json
  42
  ```

Request body: application/json

Type: object

- `currentPassword` (optional)
  Type: string
  
  Password of the currently authenticated user

Responses:

- 200: successful operation

Content type: application/json

Type: Array<RequestTwoFactorResponse>

Items:
  Reference: [RequestTwoFactorResponse](https://docs.joinpeertube.org/api-rest-reference/api/models/requesttwofactorresponse.md); Type: RequestTwoFactorResponse

- 403: invalid password

- 404: user not found

- 429: too many password checks for this user

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/users/42/two-factor/request' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "currentPassword": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "currentPassword": "string"
}`;

const response = await fetch('https://peertube2.cpy.re/api/v1/users/42/two-factor/request', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "currentPassword": "string"
}'''

response = requests.post(
    'https://peertube2.cpy.re/api/v1/users/42/two-factor/request',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Confirm two factor auth

`POST /api/v1/users/{id}/two-factor/confirm-request`

Confirm a two factor authentication request

Authentication (security requirement alternatives):

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

- 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


Parameters:

- `id` (path, id, required) - Entity id
  Type: id
  
  Schema: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md)
  
  minimum: 1
  
  Example:
  
  ```json
  42
  ```

Request body: application/json

Type: object

- `requestToken` (required)
  Type: string
  
  Token to identify the two factor request

- `otpToken` (required)
  Type: string
  
  OTP token generated by the app

Responses:

- 204: successful operation

- 403: invalid request token or OTP token

- 404: user not found

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/users/42/two-factor/confirm-request' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "requestToken": "string",
  "otpToken": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "requestToken": "string",
  "otpToken": "string"
}`;

const response = await fetch('https://peertube2.cpy.re/api/v1/users/42/two-factor/confirm-request', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "requestToken": "string",
  "otpToken": "string"
}'''

response = requests.post(
    'https://peertube2.cpy.re/api/v1/users/42/two-factor/confirm-request',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```


## Disable two factor auth

`POST /api/v1/users/{id}/two-factor/disable`

Disable two factor authentication of a user

Authentication (security requirement alternatives):

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

- 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


Parameters:

- `id` (path, id, required) - Entity id
  Type: id
  
  Schema: [id](https://docs.joinpeertube.org/api-rest-reference/api/models/id.md)
  
  minimum: 1
  
  Example:
  
  ```json
  42
  ```

Request body: application/json

Type: object

- `currentPassword` (optional)
  Type: string
  
  Password of the currently authenticated user. Users of an id and pass auth plugin must use the password they log in with

Responses:

- 204: successful operation

- 403: invalid password

- 404: user not found

- 429: too many password checks for this user

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/users/42/two-factor/disable' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "currentPassword": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "currentPassword": "string"
}`;

const response = await fetch('https://peertube2.cpy.re/api/v1/users/42/two-factor/disable', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "currentPassword": "string"
}'''

response = requests.post(
    'https://peertube2.cpy.re/api/v1/users/42/two-factor/disable',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
