# 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://sourcey-peertube.pages.dev/api-rest-reference/models/id.md)
  
  minimum: 1
  
  Example:
  
  ```json
  42
  ```

Request body: application/json (required)

Type: UpdateUser

Schema: [UpdateUser](https://sourcey-peertube.pages.dev/api-rest-reference/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://sourcey-peertube.pages.dev/api-rest-reference/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://sourcey-peertube.pages.dev/api-rest-reference/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://sourcey-peertube.pages.dev/api-rest-reference/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](#section/Password-confirmation)
  
  
  allOf:
    Reference: [currentPassword](https://sourcey-peertube.pages.dev/api-rest-reference/models/currentpassword.md); Type: currentPassword, password
    
    Password of the authenticated user, required if [password confirmation](#section/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)
```
