Create Auth Token
Create a new auth token.
HTTP Request
POST/api/users/auth_tokens
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- Authentication: Token-based (Authorization: Token <your_api_key>)
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| user_id | 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_id': 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}'Status Codes
| Code | Description |
|---|---|
| 201 | Auth token created successfully |
| 400 | Bad request — invalid input |
| 401 | Unauthorized — authentication required |
| 403 | Forbidden — insufficient permissions |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the authentication token. |
| key | String | The authentication token string. |
| user_data | Object | User information associated with token. |
| created_at | String (ISO 8601) | Timestamp when token was created. |
| updated_at | String (ISO 8601) | Timestamp when token was last updated. |
Example Response
{
"id": 1,
"key": "f4e75eab6e0f663a972d145478d6fc4b81762070",
"user_data": {
"id": 42,
"username": "johndoe",
"full_name": "John Doe",
"email": "johndoe@example.com"
},
"created_at": "2023-10-01T12:34:56Z",
"updated_at": "2023-10-01T12:34:56Z"
}
Notes
- The
keyfield contains the actual token to use in API requests. - Tokens are automatically generated and cannot be customized.