Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.

API: Users

Fasih Awan edited this page Mar 12, 2016 · 8 revisions

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.

Path

/api/users

Permissions

Only the signed in user can access or modify it. The only alternative is when a user needs to reset their forgotten password.

Fields

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

Updating

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.

Status Codes

200: The user was updated successfully 400: There were bad or missing values in the request body

Example Request

PATCH /api/users/update_details
Host: sanaprotocolbuilder.me
Authorization: Token <token>
{
    "current-password": "mypassword",
    "email": "new_email@host.com"
}

Example Response

{
    "id": 21,
    "is_superuser": false,
    "first_name": "John",
    "last_name": "Doe",
    "username": "jc123",
    "email": "new_email@host.com"
}

Get User

To get a user's details, you can send a GET request to /api/users/{id} where id is the current user's id.

Status Codes

200: Success 400: There were bad or missing values in the request body 404: User was not found

Example Request

PATCH /api/users/41
Host: sanaprotocolbuilder.me
Authorization: Token <token>

Example Response

{
    "id": 21,
    "is_superuser": false,
    "first_name": "John",
    "last_name": "Zeena",
    "username": "jc123",
    "email": "new_email@host.com"
}

Clone this wiki locally