Skip to main content

Create User

Create a new user.

HTTP Request

POST/api/users

Authorization

Authorization

  • Required: Yes
  • Permission: Staff or Admin
  • Authentication: Token-based (Authorization: Token <your_api_key>)

Request Body

FieldTypeRequiredDescription
usernameStringYesUnique username for the user.
passwordStringYesPassword for the user account.
mobile_numberStringNoMobile phone number of the user.
emailStringYesEmail address of the user (must be unique).
first_nameStringYesFirst name of the user.
last_nameStringYesLast name of the user.
genderStringNoGender of the user (`male`, `female`, non-binary).
is_staffBooleanNoWhether user has staff privileges (default: false).
is_adminBooleanNoWhether user has admin privileges (default: false).
is_activeBooleanNoWhether user account is active (default: true).
groupsArrayNoList of group IDs the user belongs to.

Example Requests

1import requests
2
3api = requests.Session()
4api.headers.update({'Authorization': 'Token f4e75eab6e0f663a972d145478d6fc4b81762070'})
5response = api.post(
6  'http://www.example.com/api/users/',
7  json={
8      'username': 'michael_chen',
9      'password': 'SecurePass123!',
10      'mobile_number': '+1-555-0156',
11      'email': 'michael.chen@techcorp.com',
12      'first_name': 'Michael',
13      'last_name': 'Chen',
14      'gender': 'male',
15      'is_staff': True,
16      'is_admin': False,
17      'is_active': True,
18      'groups': [1, 3]
19  }
20)

Status Codes

CodeDescription
201User created successfully
400Bad request — invalid input
401Unauthorized — authentication required
403Forbidden — insufficient permissions
500Internal server error

Response Fields

FieldTypeDescription
idIntegerUnique ID of the user.
usernameStringUsername of the user.
mobile_numberStringMobile phone number of the user.
emailStringEmail address of the user.
avatarStringURL to the user's avatar image (null if none).
first_nameStringFirst name of the user.
last_nameStringLast name of the user.
full_nameStringFull name (first + last name).
genderStringGender of the user.(male/female)
is_staffBooleanWhether user has staff privileges.
is_adminBooleanWhether user has admin privileges.
is_activeBooleanWhether user account is active.
last_loginString (ISO 8601)Timestamp of last login (null for new users).
created_atString (ISO 8601)Timestamp when user was created.
updated_atString (ISO 8601)Timestamp when user was last updated.
is_onlineBooleanWhether user is currently online.
groups_dataArray[Object]Array of group objects with detailed info.

Group Data Structure

FieldTypeDescription
idIntegerUnique ID of the group
nameStringName of the group

Example Response

{
"id": 42,
"username": "michael_chen",
"mobile_number": "+1-555-0156",
"email": "michael.chen@techcorp.com",
"first_name": "Michael",
"last_name": "Chen",
"gender": "male",
"avatar": "http://www.example.com/media/avatars/michael.jpg",
"full_name": "Michael Chen",
"is_staff": true,
"is_admin": false,
"is_active": true,
"last_login": null,
"created_at": "2023-01-01T12:00:00Z",
"updated_at": "2023-01-01T12:00:00Z",
"is_online": false,
"groups_data": [
{
"id": 1,
"name": "Admins"
},
{
"id": 3,
"name": "Editors"
}
]
}

Notes

    • The username and email fields must be unique.
    • The full_name field is automatically generated from first_name and last_name.
    • The groups field should contain valid group IDs that already exist in the system.