Create Auth Token
Create an auth token for a user without a token
HTTP Request
POST/api/users/auth_tokens/
NOTE: NOT USING THE TRAILING SLASH AT THE END OF THE URL RESULTS TO A 500 SERVER ERROR
Authorization
Authorization
- Required: Yes
- Permission: Staff with UserAuthTokenPermission or Admin
- Permission Code: 1241
- Authentication: Token-based (Authorization: Token <your_api_key>)
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| user | Integer | Yes | User ID to create the auth token for |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3api = requests.Session()
4api.headers.update({'Authorization': 'Token f4e75eab6e0f663a972d145478d6fc4b81762070'})
5response = api.post(
6 'http://www.example.com/api/users/auth_tokens/',
7 json={
8 'user': 42
9 }
10)1curl "http://www.example.com/api/users/auth_tokens/" -X POST -H "Authorization: Token XXXXXXXXXXXXXXXXXXXXXX" -H "Content-Type: application/json" -d '{
2 "user_id": 42
3}'Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the auth token(unique) |
| key | String | The regenerated authentication token key(unique) |
| user_data | Object | Information about the user associated with the token |
| created_at | DateTime | Timestamp when the token was created |
| updated_at | DateTime | Timestamp when the token was last updated (regenerated) |
UserData fields
| Field | Type | Description |
|---|---|---|
| id | Integer | User id(unique) |
| username | String | Username of the related user(unique) |
| mobile_number | String | User mobile number (unique) |
| first_name | String | First name of the user (nullable) |
| last_name | String | Last name of the user (nullable) |
Example Response
{
"id": 8,
"key": "96425ca2693ed75c82f520a5d19d49e2db424f7b",
"user_data": {
"id": 7,
"username": "user_96f356bd56e9fcd8148bd59d8d9b1960",
"mobile_number": "09123456789",
"first_name": null,
"last_name": null
},
"created_at": "2025-11-29T13:03:31.428690Z",
"updated_at": "2025-11-29T13:03:31.428698Z"
}
Notes
- The
keyfield contains the actual token to use in API requests. - Tokens are auto-generated and cannot be customized.
- Token creation is only possible for users without a token. Regenrating a new token is done with the
regenarateendpoint