Back

Users

Get all Users

GET /api/users/

Curl

curl 'your-edge.com/api/users/' --user username:your-password

Python

import requests

url = 'your-edge.com/api/users/'
auth = ('your-username', 'your-password')
response = requests.get(url, auth=auth)
print response.json()
    

Response

[
    {
        "id": "568d3cec9232a6ec4a5d95e5",
        "url": "http://192.168.1.10:8080/api/users/568d3cec9232a6ec4a5d95e5/",
        "date_joined": "2016-01-06T16:12:28.270000",
        "previous_login_date": null,
        "preferences": null,
        "username": "Bob",
        "first_name": null,
        "last_name": null,
        "email": "bob@example.com",
        "description": "",
        "is_active": true,
        "is_superuser": true,
        "is_staff": true,
        "can_inbox": true,
        "allow_rest_access": true,
        "organization": null,
        "memberships": [
            "WHITE",
            "GREEN",
            "AMBER",
            "RED"
        ],
        "access_tokens_url": "http://192.168.1.10:8080/api/users/568d3cec9232a6ec4a5d95e5/tokens/",
        "login_history_url": "http://192.168.1.10:8080/api/users/568d3cec9232a6ec4a5d95e5/history/"
    }
]

Headers:

Name Description
Link A comma separated list of RFC 5988 pagination links

Paramters:

Users may be filtered using the following parameters.

Name Type Description
first_name String First Name of user
last_name String Last name of user
email String User’s email address
username String User’s username
is_active Boolean Active status of the users

Note:

All string searches are fuzzy by default and will match mixed-case substrings. For instance,

/api/users/?first_name=jon

Would pull back matches for users with names such as Jon, Jonny, Jonathan, etc... Multiple parameters can be `AND`ed together to increase speicificity

/api/users/?first_name=john&last_name=doe

Retrieve Single User

GET /api/users/:id

Curl

curl 'your-edge.com/api/users/:id/' --user username:your-password

Python

import requests

url = 'your-edge.com/api/users/{id}/'
auth = ('your-username', 'your-password')
response = requests.get(url, auth=auth)
print response.json()

Response

{
    "id": "568d3cec9232a6ec4a5d95e5",
    "url": "http://192.168.1.10:8080/api/users/568d3cec9232a6ec4a5d95e5/",
    "date_joined": "2016-01-06T16:12:28.270000",
    "previous_login_date": null,
    "preferences": null,
    "username": "bob",
    "first_name": bob,
    "last_name": bob,
    "email": "bob@example.com",
    "description": "",
    "is_active": true,
    "is_superuser": true,
    "is_staff": true,
    "can_inbox": true,
    "allow_rest_access": true,
    "organization": null,
    "memberships": [
        "WHITE",
        "GREEN",
        "AMBER",
        "RED"
    ],
    "access_tokens_url": "http://192.168.1.10:8080/api/users/568d3cec9232a6ec4a5d95e5/tokens/",
    "login_history_url": "http://192.168.1.10:8080/api/users/568d3cec9232a6ec4a5d95e5/history/"
}

Create User

POST /api/users/

Curl

curl
    -u username:password
    -H "Content-Type: application/json"
    -XPOST 'your-edge.com/api/users/'
    -d '{
      "username": "myuser",
      "password": "Pass@1233",
      "first_name": "johnny",
      "last_name": "Doe",
      "email": "johnny@doe.com"
    }'

Python

import requests

url = 'your-edge.com/api/users/'
auth = ('your-username', 'your-password')
payload = {
  "username": "myuser",
  "password": "Pass@1233",
  "first_name": "johnny",
  "last_name": "Doe",
  "email": "johnny@doe.com"
}
response = requests.post(url, json=payload, auth=auth)
print response.json()

Required Arguments

{
    "username": String,
    "password": String,
    "first_name": String,
    "last_name": String,
    "email": String
}

Optional Arguments

{
    "description": String,
    "is_active": Boolean,
    "is_superuser": Boolean,
    "is_staff": Boolean,
    "can_inbox": Boolean,
    "allow_rest_access": Boolean,
    "organization": String,
    "memberships": List[String],
}

Response

{
  "id": "56e8228891aece0fe52e83ab",
  "url": "http://192.168.1.10:8080/api/users/56e8228891aece0fe52e83ab/",
  "date_joined": "2016-03-15T14:56:08.591205",
  "previous_login_date": null,
  "preferences": null,
  "username": "myuser",
  "first_name": "johnny",
  "last_name": "Doe",
  "email": "johnny@doe.com",
  "description": "",
  "is_active": true,
  "is_superuser": false,
  "is_staff": false,
  "can_inbox": true,
  "allow_rest_access": false,
  "organization": null,
  "memberships": [
    "WHITE"
  ],
  "access_tokens_url": "http://192.168.1.10:8080/api/users/56e8228891aece0fe52e83ab/tokens/",
  "login_history_url": "http://192.168.1.10:8080/api/users/56e8228891aece0fe52e83ab/history/"
}

Update User

PATCH /api/users/:id

Users are updated via HTTP PATCH rather than PUT, this allows you to supply just the fields you want to change in your request

Curl

curl
    -XPATCH 'your-edge.com/api/users/{id}/'
    -u username:password
    -H "Content-Type: application/json"
    -d '{
      "first_name":"joseph"
    }'

Python

import requests

url = 'your-edge.com/api/users/'
auth = ('your-username', 'your-password')
payload = {
  "first_name":"joseph"
}
response = requests.patch(url, json=payload, auth=auth)
print response.json()

Optional Arguments

{
    "username": String,
    "first_name": String,
    "last_name": String,
    "email": String
    "description": String,
    "is_active": Boolean,
    "is_superuser": Boolean,
    "is_staff": Boolean,
    "can_inbox": Boolean,
    "allow_rest_access": Boolean,
    "organization": String,
    "memberships": List[String],
}

Response

HTTP 202 Accepted

Delete User

DELETE /api/users/:id

Curl

curl
-XDELETE 'your-edge.com/api/users/{id}/'
-u username:password

Python

import requests

url = 'your-edge.com/api/users/{id}'
auth = ('your-username', 'your-password')
response = requests.delete(url, auth=auth)
print response.status_code

Arguments

None

Response:

HTTP 204 No Content

Get All User Tokens

GET /api/users/:id/tokens

Curl

curl
'your-edge.com/api/users/{id}/tokens/'
-u username:password

Python

import requests

url = 'your-edge.com/api/users/{id}/tokens/'
auth = ('your-username', 'your-password')
response = requests.get(url, auth=auth)
print response.json()

Response

[
    {
        "id": "56c3e52a3d7b24185cd9e566",
        "title": "Dashboard",
        "url": "http://192.168.1.10:8080/api/users/568d3cee9232a6ec51dc5fdc/tokens/56c3e52a3d7b24185cd9e566/",
        "token": "",
        "hashed_token": "$2a$10$lMhO5nFPvkdaMjyfX12jye34I7D2NIAuoOE378Kw8OL80ap4ZhZJK",
        "active": true,
        "created_on": "2016-02-17T03:12:42.746000",
        "updated_on": "2016-02-17T03:12:42.746000",
        "last_used": null,
        "expires": "2017-02-16T03:12:42.746000"
    }
]

Retrieve Single Token

GET /api/users/:id/tokens/:tokenid

Curl

curl
'your-edge.com/api/users/{id}/tokens/{tokenid}/'
-u username:password

Python

import requests

url = 'your-edge.com/api/users/{id}/tokens/{tokenid}/'
auth = ('your-username', 'your-password')
response = requests.get(url, auth=auth)
print response.json()

Response

{
    "id": "56c3e52a3d7b24185cd9e566",
    "title": "Dashboard",
    "url": "http://192.168.1.10:8080/api/users/568d3cee9232a6ec51dc5fdc/tokens/56c3e52a3d7b24185cd9e566/",
    "token": "",
    "hashed_token": "$2a$10$lMhO5nFPvkdaMjyfX12jye34I7D2NIAuoOE378Kw8OL80ap4ZhZJK",
    "active": true,
    "created_on": "2016-02-17T03:12:42.746000",
    "updated_on": "2016-02-17T03:12:42.746000",
    "last_used": null,
    "expires": "2017-02-16T03:12:42.746000"
}

Create Token

POST /api/users/:id/tokens/

Curl

curl
    -u username:password
    -H "Content-Type: application/json"
    -XPOST 'your-edge.com/api/users/:id/tokens/'
    -d '{
      "title": "My New Token"
    }'

Python

import requests

url = 'your-edge.com/api/users/{id}/tokens/'
auth = ('your-username', 'your-password')
payload = {
  "title": "My New Token"
}
response = requests.post(url, json=payload, auth=auth)
print response.json()

Required Arguments

{
    "title": String
}

Response

{
  "last_used": null,
  "title": "My New Token",
  "expires": "2017-10-18T19:49:05.238",
  "token": "db70a76277df3947cf53010974ae9d2f06efbfe6",
  "created_on": "2016-10-18T19:49:05.238",
  "user": "58066eba1078794184e40514",
  "hashed_token": "$2b$10$TepNUdVBW0PtH/tveveQa.fYIEY/3IHlKqFV.LL0pnIzu5Uxibe2K",
  "active": true,
  "updated_on": "2016-10-18T19:49:05.238",
  "id": "58067cb11078794187d3a240"
}

Update Token

PATCH /api/users/:id/tokens/:tokenid

Curl

curl
-X PATCH 'your-edge.com/api/users/:id/tokens/:tokenid/'
-u username:password
-d '{
  "active': false
}'

Python

import requests

url = 'your-edge.com/api/users/{id}/tokens/{tokenid}/'
auth = ('your-username', 'your-password')
payload = {
  "active': false
}
response = requests.patch(url, json=payload, auth=auth)
print response.json()

Arguments

{
    "active": Boolean
}

Response

HTTP 202 Accepted

Delete Token

DELETE /api/users/:id/tokens/:tokenid

Arguments

None

Response:

HTTP 204 No Content

Get All User Access History

GET /api/users/:id/history

Curl

curl
'your-edge.com/api/users/{id}/history/'
-u username:password

Python

import requests

url = 'your-edge.com/api/users/{id}/history/'
auth = ('your-username', 'your-password')
response = requests.get(url, auth=auth)
print response.json()
curl 'your-edge.com/api/users/:id/history' -H "Authorization: Token user:token"

Response:

[
    {
        "success": true,
        "user_agent": null,
        "attempted_on": "2016-02-18T02:29:34.119000",
        "remote_address": null
    }
]

 

For more information, join the conversation in the Soltra Edge Forums at forums.soltra.com.