User¶
Contents
Summary¶
Resource |
Operation |
Description |
---|---|---|
User |
Creates a new user. Requires the admin role. |
|
Gets a single user given its ID. |
||
Gets a list of all the users. |
||
Updates an existing user. Requires the admin role. |
||
Deletes a user. Requires the admin role. |
Create¶
JSON Schema
Required parameters are in bold.
type |
object |
||
properties |
|||
|
type |
string |
|
maxLength |
255 |
||
minLength |
1 |
||
|
type |
string |
|
maxLength |
50 |
||
minLength |
1 |
||
|
type |
string |
|
maxLength |
50 |
||
minLength |
1 |
||
|
type |
string |
|
minLength |
1 |
||
|
type |
array |
|
items |
|||
type |
string |
||
maxLength |
80 |
||
minLength |
1 |
||
minItems |
1 |
||
|
type |
string |
|
maxLength |
255 |
||
minLength |
1 |
||
additionalProperties |
False |
-
POST
/api/users
¶ Creates a new user. Requires the admin role.
Example request:
POST /users HTTP/1.1 Host: 127.0.0.1 Content-Type: application/json { "email": "johndoe@company.com", "first_name": "John", "last_name": "Doe", "password": "asdfasdfasdf", "roles": ["analyst"], "username": "johndoe" }
Example response:
HTTP/1.1 201 Created Content-Type: application/json { "active": true, "apikey": "11111111-1111-1111-1111-111111111111", "email": "johndoe@company.com", "first_name": "John", "id": 2, "last_name": "Doe", "roles": ["analyst"], "username": "johndoe" }
- Request Headers
Authorization – Optional Apikey value
- Response Headers
Content-Type – application/json
- Status Codes
201 Created – User created
400 Bad Request – Password does not meet length requirement
400 Bad Request – JSON does not match the schema
401 Unauthorized – Invalid role to perform this action
404 Not Found – Role not found
409 Conflict – Email address already exists
409 Conflict – Username already exists
500 Internal Server Error – Unable to add user to datastore
Read Single¶
-
GET
/api/users/
(int: user_id)¶ Gets a single user given its ID.
Example request:
GET /users/2 HTTP/1.1 Host: 127.0.0.1 Accept: application/json
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "active": true, "email": "johndoe@company.com", "first_name": "John", "id": 2, "last_name": "Doe", "roles": ["analyst"], "username": "johndoe" }
- Request Headers
Authorization – Optional Apikey value
- Response Headers
Content-Type – application/json
- Status Codes
200 OK – User found
401 Unauthorized – Invalid role to perform this action
404 Not Found – User ID not found
Read Multiple¶
-
GET
/api/users
¶ Gets a list of all the users.
Example request:
GET /users HTTP/1.1 Host: 127.0.0.1 Accept: application/json
Example response:
HTTP/1.1 200 OK Content-Type: application/json [ { "active": true, "email": "admin@localhost", "first_name": "Admin", "id": 1, "last_name": "Admin", "roles": ["admin", "analyst"], "username": "admin" }, { "active": true, "email": "johndoe@company.com", "first_name": "John", "id": 2, "last_name": "Doe", "roles": ["analyst"], "username": "johndoe" } ]
- Request Headers
Authorization – Optional Apikey value
- Response Headers
Content-Type – application/json
- Status Codes
200 OK – Users found
401 Unauthorized – Invalid role to perform this action
Update¶
JSON Schema
Required parameters are in bold.
type |
object |
||
properties |
|||
|
type |
boolean |
|
|
type |
string |
|
maxLength |
255 |
||
minLength |
1 |
||
|
type |
string |
|
maxLength |
50 |
||
minLength |
1 |
||
|
type |
string |
|
maxLength |
50 |
||
minLength |
1 |
||
|
type |
string |
|
minLength |
1 |
||
|
type |
array |
|
items |
|||
type |
string |
||
maxLength |
80 |
||
minLength |
1 |
||
minItems |
1 |
||
|
type |
string |
|
maxLength |
255 |
||
minLength |
1 |
||
additionalProperties |
False |
-
PUT
/api/users/
(int: user_id)¶ Updates an existing user. Requires the admin role.
Example request:
PUT /users/2 HTTP/1.1 Host: 127.0.0.1 Content-Type: application/json { "active": false }
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "active": false, "email": "johndoe@company.com", "first_name": "John", "id": 2, "last_name": "Doe", "roles": ["analyst"], "username": "johndoe" }
- Request Headers
Authorization – Optional Apikey value
- Response Headers
Content-Type – application/json
- Status Codes
200 OK – User updated
400 Bad Request – Password does not meet length requirement
400 Bad Request – JSON does not match the schema
401 Unauthorized – Invalid role to perform this action
404 Not Found – Role not found
404 Not Found – User ID not found
409 Conflict – Email address already exists
409 Conflict – Username already exists
Delete¶
-
DELETE
/api/users/
(int: user_id)¶ Deletes a user. Requires the admin role.
Example request:
DELETE /users/2 HTTP/1.1 Host: 127.0.0.1
Example response:
HTTP/1.1 204 No Content
- Request Headers
Authorization – Optional Apikey value
- Status Codes
204 No Content – User deleted
401 Unauthorized – Invalid role to perform this action
404 Not Found – User ID not found
409 Conflict – Unable to delete user due to foreign key constraints