Create Personal Access Token
Create a personal access token for the authenticated user.
Endpoint
POST /api/v1/auth/tokens
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <access_token> |
Content-Type | Yes | application/json |
Request Body
{
"name": "My API Token",
"scopes": ["read", "write"],
"expires_in_days": 90,
"organization_id": 1
}
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Token name/description |
scopes | array | Yes | Token scopes |
expires_in_days | integer | No | Token expiration in days (optional) |
organization_id | integer | No | Organization ID for org-scoped token |
Response
Success (201)
{
"success": true,
"data": {
"id": 1,
"name": "My API Token",
"token": "pat_abc123def456...",
"scopes": ["read", "write"],
"organization_id": 1,
"expires_at": "2024-04-01T12:00:00Z",
"created_at": "2024-01-01T12:00:00Z",
"message": "Personal access token created successfully"
},
"message": "Personal access token created successfully"
}
Error (400)
{
"success": false,
"error": {
"code": "token_creation_failed",
"message": "User is not a member of this organization"
}
}
Features
- Individual user tokens: No organization_id specified
- Organization-scoped tokens: Specify organization_id (must be member)
- Token expiration linked to organization settings for org-scoped tokens
- Token shown only once at creation
- Custom expiration support (expires_in_days)
Important Notes
WARNING: Save the token immediately after creation, it won't be shown again!
Example
curl -X POST "https://api.rivergen.com/api/v1/auth/tokens" \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
"name": "My API Token",
"scopes": ["read", "write"],
"expires_in_days": 90,
"organization_id": 1
}'
Related Endpoints
- List Tokens - List all tokens
- Update Token - Update token