Skip to content

User - Roles

Base URL: https://your-domain.com

Admin endpoints for managing user roles and permissions. All endpoints require admin authentication.


Fetch All Roles

Retrieve all roles configured in the system.

PropertyValue
EndpointFetch All Roles
MethodGET
URL/api/v1/roles
AuthenticationBearer Token

Request Headers:

HeaderValueRequired
Acceptapplication/jsonYes
AuthorizationBearer your-auth-tokenYes

Query Parameters:

ParameterTypeRequiredDescription
isp_idintegerYesISP ID
branch_idintegerYesBranch ID
user_idintegerYesUser ID

Success Response (200 OK):

json
{
    "success": true,
    "data": [
        {
            "id": 1,
            "name": "Admin",
            "user_count": 2,
            "is_system": true
        },
        {
            "id": 2,
            "name": "Staff",
            "user_count": 10,
            "is_system": false
        }
    ]
}

Fetch Role

Retrieve details of a specific role including permissions.

PropertyValue
EndpointFetch Role
MethodGET
URL/api/v1/roles/{id}
AuthenticationBearer Token

Success Response (200 OK):

json
{
    "success": true,
    "data": {
        "id": 2,
        "name": "Staff",
        "permissions": [
            "subscribers.view",
            "subscribers.create",
            "packages.view"
        ],
        "user_count": 10
    }
}

Create Role

Create a new role with specified permissions.

PropertyValue
EndpointCreate Role
MethodPOST
URL/api/v1/roles
AuthenticationBearer Token

Request Body:

json
{
    "isp_id": 1,
    "branch_id": 1,
    "user_id": 1,
    "name": "New Role",
    "permissions": ["subscribers.view", "packages.view"]
}
ParameterTypeRequiredDescription
namestringYesRole name
permissionsarrayNoArray of permission keys

Success Response (201 Created):

json
{
    "success": true,
    "message": "Role created successfully",
    "data": {
        "id": 3
    }
}

Update Role

Update role name or permissions.

PropertyValue
EndpointUpdate Role
MethodPUT
URL/api/v1/roles/{id}
AuthenticationBearer Token

Request Body:

json
{
    "name": "Updated Role",
    "permissions": ["subscribers.view", "subscribers.create"]
}

Success Response (200 OK):

json
{
    "success": true,
    "message": "Role updated successfully"
}

Delete Role

Delete a role from the system.

PropertyValue
EndpointDelete Role
MethodDELETE
URL/api/v1/roles/{id}
AuthenticationBearer Token

Success Response (200 OK):

json
{
    "success": true,
    "message": "Role deleted successfully"
}

Error Response (400 Bad Request):

json
{
    "success": false,
    "message": "Cannot delete role with assigned users"
}

Copy Role

Create a copy of an existing role with a new name.

PropertyValue
EndpointCopy Role
MethodPOST
URL/api/v1/roles/{id}/copy
AuthenticationBearer Token

Request Body:

json
{
    "isp_id": 1,
    "branch_id": 1,
    "user_id": 1,
    "name": "Copied Role"
}

Success Response (201 Created):

json
{
    "success": true,
    "message": "Role copied successfully",
    "data": {
        "id": 4
    }
}

www.onezeroart.com