Skip to main content

Rol Oluştur

Yeni rol oluşturur.

Endpoint

POST /api/v1/roles

Authentication

Bu endpoint authentication gerektirir.

Header: Authorization: Bearer \{token\}

Permission

  • admin.manage - Admin yönetim işlemleri
  • roles.create - Rol oluşturma

Request

Headers

HeaderDeğerZorunlu
AuthorizationBearer \{token\}Evet
Content-Typeapplication/jsonEvet

Request Body

ParametreTipZorunluAçıklama
namestringEvetRol adı (max: 191)
slugstringEvetRol slug'ı (unique, max: 191)
priorityintegerHayırRol önceliği (1-1000, varsayılan: 50)
is_activebooleanHayırAktif durumu (varsayılan: true)
secretstringHayırSistem rolleri için gizli anahtar

Example Request

{
"name": "Editor",
"slug": "mgmt.editor",
"priority": 40,
"is_active": true
}

Response

Success Response (201 Created)

{
"id": 5,
"name": "Editor",
"slug": "mgmt.editor",
"priority": 40,
"is_active": true,
"created_at": "2025-11-20T12:00:00.000000Z",
"updated_at": "2025-11-20T12:00:00.000000Z"
}

Error Responses

403 Forbidden

{
"message": "Rol oluşturma yetkiniz yok"
}

403 Forbidden (Hiyerarşi Kontrolü)

{
"message": "You cannot create a role with priority equal to or higher than your own role level",
"your_priority": 20,
"requested_priority": 10
}

403 Forbidden (Sistem Rolleri)

{
"message": "Forbidden role slug"
}

Code Examples

cURL

curl -X POST https://api.example.com/api/v1/roles \
-H "Authorization: Bearer \{token\}" \
-H "Content-Type: application/json" \
-d '{
"name": "Editor",
"slug": "mgmt.editor",
"priority": 40,
"is_active": true
}'

Notes

  • Kullanıcı sadece kendi seviyesinden düşük seviyeli rolleri oluşturabilir
  • Sistem rolleri (system.toor, server.root) için X-Role-Secret header'ı veya secret parametresi gereklidir
  • priority değeri belirtilmemişse varsayılan olarak 50 kullanılır