Skip to main content

Create Permission

Create a new permission in the system.

Endpoint

POST /api/Permissions

Authorization

Requires Administrator role.

Request Body

name
string
required
Unique name of the permission (e.g., “users.create”, “reports.view”)
description
string
Human-readable description of what the permission allows
module
string
required
Module or feature area this permission belongs to (e.g., “Users”, “Reports”)

Response

status
integer
HTTP status code: 201 Created
data
integer
The ID of the newly created permission
location
string
Location header with URL to the created permission: /api/permissions/{id}

Example Request

curl -X POST https://api.sapfiai.com/api/Permissions \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "users.create",
    "description": "Allows creating new users in the system",
    "module": "Users"
  }'

Example Response

42

Update Permission

Update an existing permission’s properties.

Endpoint

PUT /api/Permissions/{permissionId}

Authorization

Requires Administrator role.

Path Parameters

permissionId
integer
required
ID of the permission to update

Request Body

permissionId
integer
required
ID of the permission (must match path parameter)
name
string
required
Name of the permission
description
string
Description of the permission
module
string
required
Module the permission belongs to
isActive
boolean
required
Whether the permission is active

Response

status
integer
HTTP status code: 204 No Content on success

Example Request

curl -X PUT https://api.sapfiai.com/api/Permissions/42 \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "permissionId": 42,
    "name": "users.create",
    "description": "Allows creating and inviting new users",
    "module": "Users",
    "isActive": true
  }'

Delete Permission

Delete a permission from the system.
Deleting a permission will remove it from all roles. This action cannot be undone.

Endpoint

DELETE /api/Permissions/{permissionId}

Authorization

Requires Administrator role.

Path Parameters

permissionId
integer
required
ID of the permission to delete

Response

status
integer
HTTP status code: 204 No Content on success

Example Request

curl -X DELETE https://api.sapfiai.com/api/Permissions/42 \
  -H "Authorization: Bearer YOUR_TOKEN"

Get All Permissions

Retrieve a list of all permissions in the system.

Endpoint

GET /api/Permissions

Authorization

Requires Administrator role.

Query Parameters

activeOnly
boolean
default:"false"
When set to true, returns only active permissions

Response

permissions
array
Array of permission objects

Example Request

# Get all permissions
curl -X GET https://api.sapfiai.com/api/Permissions \
  -H "Authorization: Bearer YOUR_TOKEN"

# Get only active permissions
curl -X GET "https://api.sapfiai.com/api/Permissions?activeOnly=true" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response

[
  {
    "id": 1,
    "name": "users.create",
    "description": "Allows creating new users in the system",
    "module": "Users",
    "isActive": true,
    "createdAt": "2024-01-15T10:30:00Z"
  },
  {
    "id": 2,
    "name": "users.read",
    "description": "Allows viewing user information",
    "module": "Users",
    "isActive": true,
    "createdAt": "2024-01-15T10:31:00Z"
  },
  {
    "id": 3,
    "name": "reports.export",
    "description": "Allows exporting reports to various formats",
    "module": "Reports",
    "isActive": true,
    "createdAt": "2024-01-15T10:32:00Z"
  }
]

Get Permission by ID

Retrieve details of a specific permission.

Endpoint

GET /api/Permissions/{permissionId}

Authorization

Requires Administrator role.

Path Parameters

permissionId
integer
required
ID of the permission to retrieve

Response

id
integer
Permission ID
name
string
Permission name
description
string
Permission description
module
string
Module name
isActive
boolean
Whether the permission is active
createdAt
string
ISO 8601 timestamp

Example Request

curl -X GET https://api.sapfiai.com/api/Permissions/1 \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response

{
  "id": 1,
  "name": "users.create",
  "description": "Allows creating new users in the system",
  "module": "Users",
  "isActive": true,
  "createdAt": "2024-01-15T10:30:00Z"
}

Assign Permission to Role

Assign a permission to a specific role.

Endpoint

POST /api/Permissions/assign

Authorization

Requires Administrator role.

Request Body

roleId
string
required
ID of the role to assign the permission to
permissionId
integer
required
ID of the permission to assign
assignedBy
string
User ID of the administrator making the assignment (optional)

Response

status
integer
HTTP status code: 204 No Content on success

Example Request

curl -X POST https://api.sapfiai.com/api/Permissions/assign \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "roleId": "550e8400-e29b-41d4-a716-446655440000",
    "permissionId": 1,
    "assignedBy": "auth0|admin123"
  }'

Remove Permission from Role

Remove a permission assignment from a role.

Endpoint

POST /api/Permissions/remove

Authorization

Requires Administrator role.

Request Body

roleId
string
required
ID of the role to remove the permission from
permissionId
integer
required
ID of the permission to remove

Response

status
integer
HTTP status code: 204 No Content on success

Example Request

curl -X POST https://api.sapfiai.com/api/Permissions/remove \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "roleId": "550e8400-e29b-41d4-a716-446655440000",
    "permissionId": 1
  }'

Get Role Permissions

Retrieve all permissions assigned to a specific role.

Endpoint

GET /api/Permissions/role/{roleId}

Authorization

Requires Administrator role.

Path Parameters

roleId
string
required
ID of the role to retrieve permissions for

Response

permissions
array
Array of permission objects assigned to the role

Example Request

curl -X GET https://api.sapfiai.com/api/Permissions/role/550e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response

[
  {
    "id": 1,
    "name": "users.create",
    "description": "Allows creating new users in the system",
    "module": "Users",
    "isActive": true,
    "createdAt": "2024-01-15T10:30:00Z"
  },
  {
    "id": 2,
    "name": "users.read",
    "description": "Allows viewing user information",
    "module": "Users",
    "isActive": true,
    "createdAt": "2024-01-15T10:31:00Z"
  }
]

Common Workflows

Setup Role with Full Module Access

// Create permissions for a module
var modulePermissions = new[]
{
    new { Name = "documents.create", Description = "Create documents", Module = "Documents" },
    new { Name = "documents.read", Description = "View documents", Module = "Documents" },
    new { Name = "documents.update", Description = "Update documents", Module = "Documents" },
    new { Name = "documents.delete", Description = "Delete documents", Module = "Documents" }
};

var permissionIds = new List<int>();

// Create each permission
foreach (var perm in modulePermissions)
{
    var content = new StringContent(
        JsonSerializer.Serialize(perm),
        Encoding.UTF8,
        "application/json"
    );
    
    var response = await client.PostAsync(
        "https://api.sapfiai.com/api/Permissions",
        content
    );
    
    var permId = int.Parse(await response.Content.ReadAsStringAsync());
    permissionIds.Add(permId);
}

// Assign all permissions to a role
var roleId = "550e8400-e29b-41d4-a716-446655440000";
foreach (var permId in permissionIds)
{
    var assignCommand = new
    {
        RoleId = roleId,
        PermissionId = permId
    };
    
    await client.PostAsync(
        "https://api.sapfiai.com/api/Permissions/assign",
        new StringContent(
            JsonSerializer.Serialize(assignCommand),
            Encoding.UTF8,
            "application/json"
        )
    );
}

Error Responses

400
error
Bad Request - Invalid request parameters or permission already exists
{
  "errors": {
    "Name": ["Permission name already exists"],
    "Module": ["Module is required"]
  }
}
404
error
Not Found - Permission or role not found
409
error
Conflict - Permission already assigned to role (for assign) or not assigned (for remove)

Build docs developers (and LLMs) love