Skip to content

Create User

POST /api/user

Required privilege: Users / Edit Content-Type: application/json CSRF header required: X-XSRF-TOKEN


Request Body

{
  "User Fullname": "John Smith",
  "Username": "john.smith@acme.com",
  "User Email": "john.smith@acme.com",
  "User Phone": "+1 555 111 2222",
  "Role Id": 3,
  "password": "initial-password-123"
}
Field Type Required Description
User Fullname string Yes Display name
Username string Yes Login username - must be unique
User Email string Yes Email address - must be unique
User Phone string No Phone number
Role Id integer Yes Role to assign - see List Roles
password string Yes Initial password - minimum 8 characters

Response

HTTP/1.1 200 OK

{
  "message": "User created successfully.",
  "id": 42
}

Errors

Status Code Description
400 User.AlreadyExists Username or email already in use
400 User.PasswordTooShort Password shorter than 8 characters
400 Role.NotFound No role with the given Role Id
403 User.NotPrivileged Insufficient privilege

Code Examples

CSRF=$(grep csrf_access_token cookies.txt | awk '{print $NF}')
curl -b cookies.txt -X POST https://acme.knosc.com/api/user \
  -H "Content-Type: application/json" \
  -H "X-XSRF-TOKEN: $CSRF" \
  -d '{
    "User Fullname": "John Smith",
    "Username": "john.smith@acme.com",
    "User Email": "john.smith@acme.com",
    "Role Id": 3,
    "password": "initial-password-123"
  }'
csrf = session.cookies.get("csrf_access_token")
response = session.post(
    "https://acme.knosc.com/api/user",
    headers={"X-XSRF-TOKEN": csrf},
    json={
        "User Fullname": "John Smith",
        "Username": "john.smith@acme.com",
        "User Email": "john.smith@acme.com",
        "Role Id": 3,
        "password": "initial-password-123"
    }
)
print(response.json())