# Register a user

`POST /api/v1/users/register`

Signup has to be enabled and signup approval is not required

Authentication: no security requirement declared for this operation.

Request body: application/json (required)

Type: RegisterUser

Schema: [RegisterUser](https://sourcey-peertube.pages.dev/api-rest-reference/models/registeruser.md)

- `username` (required)
  Type: username
  
  immutable name of the user, used to find or mention its actor
  
  allOf:
    Reference: [username](https://sourcey-peertube.pages.dev/api-rest-reference/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://sourcey-peertube.pages.dev/api-rest-reference/models/password.md); Type: password, password
  
  minLength: 6
  
  maxLength: 50

- `email` (required)
  Type: string, email
  
  email of the user, used for login or service communications

- `displayName` (optional)
  Type: string
  
  editable name of the user, displayed in its representations
  
  minLength: 1
  
  maxLength: 120

- `channel` (optional)
  Type: object
  
  channel base information used to create the first channel of the user
  
  - `name` (optional)
    Reference: [usernameChannel](https://sourcey-peertube.pages.dev/api-rest-reference/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"
    ```
  
  - `displayName` (optional)
    Type: string

- `signupClient` (optional)
  Type: string
  
  **PeerTube >= 9.0** Client used to sign up. If set, links of the verification and registration accepted emails
  make the web client propose to open this client
  
  
  enum: ["peertube-app"]

Responses:

- 200: successful operation

Content type: application/json

Type: object

- `state` (optional)
  Type: object
  
  - `id` (optional)
    Reference: [UserRegistrationState](https://sourcey-peertube.pages.dev/api-rest-reference/models/userregistrationstate.md); Type: UserRegistrationState
    
    The registration state (Pending = `1`, Rejected = `2`, Accepted = `3`)
    
    enum: [1,2,3]
  
  - `label` (optional)
    Type: string

- 400: request error

- 403: user registration is not enabled, user limit is reached, registration is not allowed for the ip, requires approval or blocked by a plugin

- 409: a user with this username, channel name or email already exists

## Examples

### cURL

```bash
curl -X POST 'https://peertube2.cpy.re/api/v1/users/register' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "password": "********",
  "email": "user@example.com",
  "displayName": "string",
  "channel": {
    "name": "framasoft_videos",
    "displayName": "string"
  },
  "signupClient": "peertube-app"
}'
```

### JavaScript

```javascript
const body = `{
  "password": "********",
  "email": "user@example.com",
  "displayName": "string",
  "channel": {
    "name": "framasoft_videos",
    "displayName": "string"
  },
  "signupClient": "peertube-app"
}`;

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

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

### Python

```python
import requests

body = '''{
  "password": "********",
  "email": "user@example.com",
  "displayName": "string",
  "channel": {
    "name": "framasoft_videos",
    "displayName": "string"
  },
  "signupClient": "peertube-app"
}'''

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