-
Notifications
You must be signed in to change notification settings - Fork 7
API: Users
This page will detail how to work with the User model. The User model is created when a user creates an account, which is covered under API: Authentication - Sign up.
/api/users
Only the signed in user can access or modify it. The only alternative is when a user needs to reset their forgotten password.
| Field Name | Type | Required? | Default Value | Read Only? | Description |
|---|---|---|---|---|---|
email |
string |
Yes | No | The user's email address which is specified during registration | |
first_name |
string |
No | '' | No | The user's first name |
last_name |
string |
No | '' | No | The user's last name |
password |
string |
Yes | No | The user's password, encrypted before saved | |
is_superuser |
boolean |
No | false |
No | Flag that is used to determine if user has escalated permissions |
date_joined |
datetime |
Yes | Yes | The time the object is created. It is auto-generated |
To update a user's information, you can send a PATCH request to /api/users/update_details. There is no need to put any identifiers in the URL, all of that will go in the body. The user's current password is a required field in the request.
200: The user was updated successfully 400: There were bad or missing values in the request body
PATCH /api/users/update_details
Host: sanaprotocolbuilder.me
Authorization: Token <token>{
"current-password": "mypassword",
"email": "new_email@host.com"
}{
"id": 21,
"is_superuser": false,
"first_name": "John",
"last_name": "Doe",
"username": "jc123",
"email": "new_email@host.com"
}To get a user's details, you can send a GET request to /api/users/{id} where id is the current user's id.
200: Success 400: There were bad or missing values in the request body 404: User was not found
PATCH /api/users/41
Host: sanaprotocolbuilder.me
Authorization: Token <token>{
"id": 21,
"is_superuser": false,
"first_name": "John",
"last_name": "Zeena",
"username": "jc123",
"email": "new_email@host.com"
}