Documentation

User List API Endpoint

Make a GET request to this resource to retrieve the list of users.

GET /api/v2/users/
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
X-API-Node: localhost
X-API-Time: 0.097s


{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 1,
            "type": "user",
            "url": "/api/v2/users/1/",
            "related": {
                "admin_of_organizations": "/api/v2/users/1/admin_of_organizations/",
                "organizations": "/api/v2/users/1/organizations/",
                "roles": "/api/v2/users/1/roles/",
                "access_list": "/api/v2/users/1/access_list/",
                "teams": "/api/v2/users/1/teams/",
                "credentials": "/api/v2/users/1/credentials/",
                "activity_stream": "/api/v2/users/1/activity_stream/",
                "projects": "/api/v2/users/1/projects/"
            },
            "summary_fields": {
                "user_capabilities": {
                    "edit": true,
                    "delete": false
                }
            },
            "created": "2017-09-06T02:55:30.492Z",
            "username": "admin",
            "first_name": "",
            "last_name": "",
            "email": "[email protected]",
            "is_superuser": true,
            "is_system_auditor": false,
            "ldap_dn": "",
            "external_account": null,
            "auth": []
        }
    ]
}

The resulting data structure contains:

{
    "count": 99,
    "next": null,
    "previous": null,
    "results": [
        ...
    ]
}

The count field indicates the total number of users found for the given query. The next and previous fields provides links to additional results if there are more than will fit on a single page. The results list contains zero or more user records.

Results

Each user data structure includes the following fields:

  • id: Database ID for this user. (integer)
  • type: Data type for this user. (multiple choice)
  • url: URL for this user. (string)
  • related: Data structure with URLs of related resources. (object)
  • summary_fields: Data structure with name/description for related resources. (object)
  • created: Timestamp when this user was created. (datetime)
  • username: Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters (string)
  • first_name: (string)
  • last_name: (string)
  • email: (email)
  • is_superuser: Designates that this user has all permissions without explicitly assigning them. (boolean)
  • is_system_auditor: (boolean)
  • ldap_dn: (string)
  • external_account: Set if the account is managed by an external service (field)

Sorting

To specify that users are returned in a particular order, use the order_by query string parameter on the GET request.

?order_by=name

Prefix the field name with a dash - to sort in reverse:

?order_by=-name

Multiple sorting fields may be specified by separating the field names with a comma ,:

?order_by=name,some_other_field

Searching

Use the search query string parameter to perform a case-insensitive search within all designated text fields of a model.

?search=findme

Search across related fields (added in AWX 1.4 / Ansible Tower 3.1):

?related__search=findme

Filtering

Any additional query string parameters may be used to filter the list of results returned to those matching a given value. Only fields and relations that exist in the database may be used for filtering. Any special characters in the specified value should be URL-encoded. For example:

?field=value%20xyz

Fields may also span relations, only for fields and relationships defined in the database:

?other__field=value

To exclude results matching certain criteria, prefix the field parameter with not__:

?not__field=value

By default, all query string filters are AND’ed together, so only the results matching all filters will be returned (added in AWX 1.4). To combine results matching any one of multiple criteria, prefix each query string parameter with or__:

?or__field=value&or__field=othervalue
?or__not__field=value&or__field=othervalue

The default AND filtering applies all filters simultaneously to each related object being filtered across database relationships (added in Ansible Tower 1.4.5). The chain filter instead applies filters separately for each related object. To use, prefix the query string parameter with chain__:

?chain__related__field=value&chain__related__field2=othervalue
?chain__not__related__field=value&chain__related__field2=othervalue

If the first query above were written as ?related__field=value&related__field2=othervalue, it would return only the primary objects where the same related object satisfied both conditions. As written using the chain filter, it would return the intersection of primary objects matching each condition.

Field lookups may also be used for more advanced queries, by appending the lookup to the field name:

?field__lookup=value

The following field lookups are supported:

  • exact: Exact match (default lookup if not specified).
  • iexact: Case-insensitive version of exact.
  • contains: Field contains value.
  • icontains: Case-insensitive version of contains.
  • startswith: Field starts with value.
  • istartswith: Case-insensitive version of startswith.
  • endswith: Field ends with value.
  • iendswith: Case-insensitive version of endswith.
  • regex: Field matches the given regular expression.
  • iregex: Case-insensitive version of regex.
  • gt: Greater than comparison.
  • gte: Greater than or equal to comparison.
  • lt: Less than comparison.
  • lte: Less than or equal to comparison.
  • isnull: Check whether the given field or related object is null; expects a boolean value.
  • in: Check whether the given field’s value is present in the list provided; expects a list of items.

Boolean values may be specified as True or 1 for true, False or 0 for false (both case-insensitive).

Null values may be specified as None or Null (both case-insensitive), though it is preferred to use the isnull lookup to explicitly check for null values.

Lists (for the in lookup) may be specified as a comma-separated list of values.

Filtering based on the requesting user’s level of access by query string parameter (added in Ansible Tower 3.1).

  • role_level: Level of role to filter on, such as admin_role

Create Users

Make a POST request to this resource with the following user fields to create a new user:

  • username: Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters (string, required)
  • first_name: (string, default=””)
  • last_name: (string, default=””)
  • email: (email, default=””)
  • is_superuser: Designates that this user has all permissions without explicitly assigning them. (boolean, default=false)
  • is_system_auditor: (boolean, default=false)
  • password: Write-only field used to change the password. (string, default=””)

Reviewing the Options Endpoint

The Options Endpoint table offers a view of the Options for this endpoint. When viewing the endpoint in the browsable API, clicking the “Options” button gives you the raw JSON for the following:

name User List
description # List Users: Make a GET request to this resource to retrieve the list of users.
renders
0 application/json
1 text/html
parses
0 application/json
added_in_version 1.2
actions
POST
username
type string
required
true
label Username
help_text Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ only.
max_length 30
first_name
type string
required
false
label First name
max_length 30
last_name
type string
required
false
label Last name
max_length 30
email
type string
required
false
label Email address
max_length 254
is_superuser
type boolean
required
false
label Superuser status
help_text Designates that this user has all permissions without explicitly assigning them.
default
false
is_system_auditor
type boolean
required
false
label Is system auditor
default
false
password
type string
required
false
label Password
help_text Write-only field used to change the password.
default (Empty Text)
write_only
true
GET
id
type integer
label ID
help_text Database ID for this user.
type
type choice
help_text Data type for this user.
choices
0
0 user
1 User
url
type string
label URL
help_text URL for this user.
related
type object
label Related
help_text Data structure with URLs of related resources.
summary_fields
type object
label Summary fields
help_text Data structure with name/description for related resources.
created
type datetime
label Created
help_text Timestamp when this user was created.
username
type string
label Username
help_text Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ only.
first_name
type string
label First name
last_name
type string
label Last name
email
type string
label Email address
is_superuser
type boolean
label Superuser status
help_text Designates that this user has all permissions without explicitly assigning them.
is_system_auditor
type boolean
label Is system auditor
ldap_dn
type string
label Ldap dn
external_account
type field
label External account
help_text Set if the account is managed by an external service.
types
0 user
search_fields
0 username
1 first_name
2 last_name
3 email