Skip to content

Access Roles Service API

Overview

The Access Roles Service API manages role-based access control (RBAC) in a multi-tenant environment. It enables businesses to:

  • Create and manage roles
  • Assign roles to users
  • Control access to modules and services
  • Manage user permissions across different tenants

API Documentation

Base URL

https://apis.prayog.io/access-roles-service/api/v1

Authentication

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant ID for multi-tenant supporttest-tenant
X-USER-IDYes*User ID for operationstest-user
AuthorizationYes*Bearer token for RBAC serviceBearer <token>

*Required for specific endpoints only

Available Endpoints

Roles Management

  1. POST /roles - Create a new role
  2. GET /roles - List roles with pagination
  3. GET /roles/:id - Get role details
  4. GET /roles/:id/modules - Get role’s module access
  5. PATCH /roles/:id - Update a role
  6. DELETE /roles/:id - Delete a role
  7. PUT /roles/:id/users - Assign users to role
  8. GET /roles/:id/users - Get users in role
  9. GET /roles/:id/users/check - Check user assignments

User Management

  1. PUT /users/:userId/roles - Assign roles to a user
  2. DELETE /users/:userId/roles - Revoke role from a user
  3. GET /users/:userId/roles - Get user’s roles
  4. GET /users/modules - Get user’s module access
  5. GET /users/search/tenants - Search user tenant access
  6. GET /users/tenant - Get all users for a tenant

System Endpoints

  1. GET /data/services - Get all services with their modules
  2. GET /data/modules - Get all modules
  3. GET /health - Health check endpoint

API Endpoints

1. Health Check

Checks the health status of the service and its dependencies.

GET /health
Example Curl Command
Terminal window
curl --location 'http://localhost:9021/access-roles-service/api/v1/health'
Success Response (200 OK)
{
"success": true,
"message": "Service is healthy",
"data": {
"status": "ok",
"version": "0.1.0",
"timestamp": "2025-06-04T07:59:17.404Z",
"database": {
"name": "rbca",
"host": "mongodb+srv://app_dev_user_prayogrbca:****@prayogdevqa.em5uh.mongodb.net/rbca",
"connected": true,
"collections": ["Users", "Modules", "Services", "Tenants", "test", "APIKeys", "UserRoles", "APIs", "Roles"]
}
}
}

2. List Roles

Retrieves a paginated list of roles for a tenant.

GET /roles

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant
Example Curl Command
Terminal window
curl --location 'http://localhost:9021/access-roles-service/api/v1/roles' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
{
"success": true,
"message": "Roles found",
"data": {
"items": [
{
"_id": "683eb9b6a5c11d9c6556bd69",
"name": "Manager",
"description": "Will manage",
"tenantId": "682581255a53dbe3ffb4fe49",
"moduleIds": [],
"userCount": 0,
"moduleCount": 0,
"permissionsCount": 0
},
{
"_id": "683eb949a5c11d9c6556bd57",
"name": "Operator",
"description": "Will operator all bookings",
"tenantId": "682581255a53dbe3ffb4fe49",
"moduleIds": ["68303804b5a0a90fe57f5185", "683038f3b5a0a90fe57f5187"],
"userCount": 1,
"moduleCount": 21,
"permissionsCount": 21
}
],
"total": 4,
"page": 1,
"limit": 10,
"totalPages": 1
}
}

3. Create Role

Creates a new role in the specified tenant.

POST /roles

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant
X-USER-IDYesUser ID for audit trackingtest-user
Content-TypeYesMust be application/jsonapplication/json
Request Body
{
"name": "Admin",
"description": "Administrator role with full access",
"moduleIds": ["module1", "module2"]
}
Example Curl Command
Terminal window
curl --location --request POST 'http://localhost:9021/access-roles-service/api/v1/roles' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49' \
--header 'X-USER-ID: test-user' \
--header 'Content-Type: application/json' \
--data '{
"name": "Admin",
"description": "Administrator role with full access",
"moduleIds": ["module1", "module2"]
}'
Success Response (201 Created)
{
"success": true,
"message": "Role created successfully",
"data": {
"id": "683833bb76b2421e19398860",
"name": "Admin",
"description": "Administrator role with full access",
"tenantId": "test-tenant",
"moduleIds": ["module1", "module2"],
"createdAt": "2024-04-04T11:31:09Z",
"updatedAt": "2024-04-04T11:31:09Z"
}
}
Error Responses

400 Bad Request

{
"success": false,
"message": "Validation failed",
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid input data"
}
}

409 Conflict

{
"success": false,
"message": "A role with this name already exists for this tenant",
"error": {
"code": "ROLE_ALREADY_EXISTS",
"message": "A role with this name already exists for this tenant"
}
}

4. Get Role Details

Retrieves details of a specific role.

GET /roles/:id

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant

Path Parameters

ParameterTypeDescriptionExample
idstringRole ID683833bb76b2421e19398860
Example Curl Command
Terminal window
curl --location 'http://localhost:9021/access-roles-service/api/v1/roles/683eb9b6a5c11d9c6556bd69' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
{
"success": true,
"message": "Role found",
"data": {
"_id": "683eb9b6a5c11d9c6556bd69",
"name": "Manager",
"description": "Will manage",
"tenantId": "682581255a53dbe3ffb4fe49",
"moduleIds": [],
"userCount": 0,
"moduleCount": 0
}
}
Error Responses

404 Not Found

{
"success": false,
"message": "Role not found",
"error": {
"code": "NOT_FOUND",
"message": "Role not found"
}
}

5. Get Role Module Access

Retrieves the modules accessible to a role, grouped by service.

GET /roles/:id/modules

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant
AuthorizationYesBearer tokenBearer <token>

Path Parameters

ParameterTypeDescriptionExample
idstringRole ID683833bb76b2421e19398860
Example Curl Command
Terminal window
curl --location 'http://localhost:9021/access-roles-service/api/v1/roles/683eb949a5c11d9c6556bd57/modules' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
{
"success": true,
"message": "Role modules found",
"data": [
{
"serviceId": "68302e7bb5a0a90fe57f5184",
"serviceName": "Roles and Permissions",
"modules": [
{
"id": "68303804b5a0a90fe57f5185",
"name": "Create Role",
"hasAccess": true
},
{
"id": "683038f3b5a0a90fe57f5187",
"name": "View All Roles",
"hasAccess": true
}
],
"totalModules": 4,
"accessModules": 4,
"noAccessModules": 0,
"permissionsLabel": "4 permissions",
"hasServiceAccess": true
}
]
}
Error Responses

404 Not Found

{
"success": false,
"message": "Role not found",
"error": {
"code": "NOT_FOUND",
"message": "Role not found"
}
}

6. Update Role

Updates an existing role’s details.

PATCH /roles/:id

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant
X-USER-IDYesUser ID for audit trackingtest-user
Content-TypeYesMust be application/jsonapplication/json

Path Parameters

ParameterTypeDescriptionExample
idstringRole ID683833bb76b2421e19398860
Request Body
{
"name": "Manager Updated",
"description": "Updated description for Manager"
}
Example Curl Command
Terminal window
curl --location --request PATCH 'http://localhost:9021/access-roles-service/api/v1/roles/683eb9b6a5c11d9c6556bd69' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49' \
--header 'X-USER-ID: test-user' \
--header 'Content-Type: application/json' \
--data '{
"name": "Manager Updated",
"description": "Updated description for Manager"
}'
Success Response (200 OK)
{
"success": true,
"message": "Role updated successfully",
"data": {
"_id": "683eb9b6a5c11d9c6556bd69",
"name": "Manager Updated",
"description": "Updated description for Manager",
"tenantId": "682581255a53dbe3ffb4fe49",
"moduleIds": []
}
}
Error Responses

404 Not Found

{
"success": false,
"message": "Role not found",
"error": {
"code": "NOT_FOUND",
"message": "Role not found"
}
}

409 Conflict

{
"success": false,
"message": "A role with this name already exists for this tenant",
"error": {
"code": "ROLE_ALREADY_EXISTS",
"message": "A role with this name already exists for this tenant"
}
}

7. Delete Role

Deletes a role from the system.

DELETE /roles/:id

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant
X-USER-IDYesUser ID for audit trackingtest-user

Path Parameters

ParameterTypeDescriptionExample
idstringRole ID683833bb76b2421e19398860
Example Curl Command
Terminal window
curl --location --request DELETE 'http://localhost:9021/access-roles-service/api/v1/roles/683ffd98bd9577d534283496' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49' \
--header 'X-USER-ID: test-user'
Success Response (200 OK)
{
"success": true,
"message": "Role deleted successfully",
"data": null
}
Error Responses

404 Not Found

{
"success": false,
"message": "Role not found",
"error": {
"code": "NOT_FOUND",
"message": "Role not found"
}
}

8. Assign Users to Role

Assigns users to a specific role.

PUT /roles/:id/users

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant
X-USER-IDYesUser ID for audit trackingtest-user
AuthorizationYesBearer tokenBearer <token>
Content-TypeYesMust be application/jsonapplication/json

Path Parameters

ParameterTypeDescriptionExample
idstringRole ID683833bb76b2421e19398860
Request Body
{
"users": [
{ "userId": "user1" }
]
}
Example Curl Command
Terminal window
curl --location --request PUT 'http://localhost:9021/access-roles-service/api/v1/roles/683eb9b6a5c11d9c6556bd69/users' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49' \
--header 'X-USER-ID: test-user' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{"users":[{"userId":"user1"}]}'
Success Response (200 OK)
{
"success": true,
"message": "Users assigned to role successfully",
"data": null
}
Error Responses

404 Not Found

{
"success": false,
"message": "Role not found",
"error": {
"code": "NOT_FOUND",
"message": "Role not found"
}
}

9. Get Users in Role

Retrieves all users assigned to a specific role.

GET /roles/:id/users

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant

Path Parameters

ParameterTypeDescriptionExample
idstringRole ID683833bb76b2421e19398860
Example Curl Command
Terminal window
curl --location 'http://localhost:9021/access-roles-service/api/v1/roles/683eb949a5c11d9c6556bd57/users' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
{
"success": true,
"message": "Users for role found successfully",
"data": [
{
"_id": "51f32d0a-1011-7066-d410-60fe56133550",
"name": "Akash Sharma",
"username": "mockuser22@yopmail.com",
"assignedAt": "2025-06-03T09:11:50.417Z",
"assignedBy": "b1331d7a-a081-70ec-6c9d-a8d96203c377",
"tenantId": "682581255a53dbe3ffb4fe49",
"isAssigned": true
}
],
"total": 1,
"page": 1,
"limit": 10
}
Response Fields
FieldTypeDescription
data[]._idstringUser ID
data[].namestringUser’s full name
data[].usernamestringUser’s email/username
data[].assignedAtstringISO timestamp when the user was assigned to the role
data[].assignedBystringUser ID of the person who assigned the role
data[].tenantIdstringTenant ID the user belongs to
data[].isAssignedbooleanWhether the user is assigned to the role
totalnumberTotal number of users found
pagenumberCurrent page number
limitnumberNumber of items per page
Error Responses

404 Not Found

{
"success": false,
"message": "Role not found",
"error": {
"code": "NOT_FOUND",
"message": "Role not found"
}
}

10. Check User Assignments

Checks which users are assigned to a specific role, with optional search functionality.

GET /roles/:id/users/check

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant ID682581255a53dbe3ffb4fe49

Path Parameters

ParameterTypeDescriptionExample
idstringRole ID683eb949a5c11d9c6556bd57

Query Parameters

ParameterRequiredTypeDescriptionDefault
searchNostringSearch term for filtering users by name or username-
pageNointegerPage number1
limitNointegerItems per page10
Example Curl Command
Terminal window
curl --location 'http://localhost:9021/access-roles-service/api/v1/roles/683eb949a5c11d9c6556bd57/users/check' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
{
"success": true,
"message": "Users for role found successfully",
"data": [
{
"_id": "51f32d0a-1011-7066-d410-60fe56133550",
"name": "Akash Sharma",
"username": "mockuser22@yopmail.com",
"tenantId": "682581255a53dbe3ffb4fe49",
"isAssigned": true,
"assignedAt": "2025-06-03T09:11:50.417Z",
"assignedBy": "b1331d7a-a081-70ec-6c9d-a8d96203c377"
}
],
"total": 1,
"page": 1,
"limit": 10
}
Response Fields
FieldTypeDescription
data[]._idstringUser ID
data[].namestringUser’s full name
data[].usernamestringUser’s email/username
data[].tenantIdstringTenant ID the user belongs to
data[].isAssignedbooleanWhether the user is assigned to the role
data[].assignedAtstringISO timestamp when the user was assigned to the role
data[].assignedBystringUser ID of the person who assigned the role
totalnumberTotal number of users found
pagenumberCurrent page number
limitnumberNumber of items per page

11. Assign Roles to User

Assigns one or more roles to a user within a specific tenant context.

PUT /users/:userId/roles

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant
AuthorizationYesBearer tokenBearer <token>
Content-TypeYesMust be application/jsonapplication/json

Path Parameters

ParameterTypeDescriptionExample
userIdstringUser ID to assign roles tob1331d7a-a081-70ec-6c9d-a8d96203c377
Request Body
{
"roles": [
{
"roleId": "683eb9b6a5c11d9c6556bd69"
}
]
}
Example Curl Command
Terminal window
curl --location --request PUT 'http://localhost:9021/access-roles-service/api/v1/users/b1331d7a-a081-70ec-6c9d-a8d96203c377/roles' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"roles": [
{
"roleId": "683eb9b6a5c11d9c6556bd69"
}
]
}'
Success Response (200 OK)
{
"success": true,
"message": "Role assigned successfully",
"data": null
}
Error Responses

404 Not Found

{
"success": false,
"message": "User or role not found",
"error": {
"code": "NOT_FOUND",
"message": "User or role not found"
}
}

12. Revoke Role from User

Revokes a role from a user within a specific tenant context.

DELETE /users/:userId/roles

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant
AuthorizationYesBearer tokenBearer <token>
Content-TypeYesMust be application/jsonapplication/json

Path Parameters

ParameterTypeDescriptionExample
userIdstringUser ID to revoke role fromb1331d7a-a081-70ec-6c9d-a8d96203c377
Request Body
{
"roleId": "683eb9b6a5c11d9c6556bd69"
}
Example Curl Command
Terminal window
curl --location --request DELETE 'http://localhost:9021/access-roles-service/api/v1/users/b1331d7a-a081-70ec-6c9d-a8d96203c377/roles' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"roleId": "683eb9b6a5c11d9c6556bd69"
}'
Success Response (200 OK)
{
"success": true,
"message": "Role revoked successfully",
"data": null
}
Error Responses

404 Not Found

{
"success": false,
"message": "User or role not found",
"error": {
"code": "NOT_FOUND",
"message": "User or role not found"
}
}

13. Get User’s Roles

Retrieves all roles assigned to a user, with optional filtering by tenant.

GET /users/:userId/roles

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant ID682581255a53dbe3ffb4fe49

Path Parameters

ParameterTypeDescriptionExample
userIdstringUser ID to get roles for51f32d0a-1011-7066-d410-60fe56133550

Query Parameters

ParameterRequiredTypeDescriptionDefault
tenantIdNostringFilter roles by tenant ID-
Example Curl Command
Terminal window
curl --location 'http://localhost:9021/access-roles-service/api/v1/users/51f32d0a-1011-7066-d410-60fe56133550/roles' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
{
"success": true,
"message": "User roles found",
"data": [
{
"userId": "51f32d0a-1011-7066-d410-60fe56133550",
"roleId": "683eb949a5c11d9c6556bd57",
"tenantId": "682581255a53dbe3ffb4fe49",
"assignedAt": "2025-06-03T09:11:50.417Z",
"assignedBy": "b1331d7a-a081-70ec-6c9d-a8d96203c377",
"role": {
"name": "Operator",
"description": "Will operator all bokings",
"moduleIds": [
"68303804b5a0a90fe57f5185",
"683038f3b5a0a90fe57f5187"
]
}
}
]
}
Response Fields
FieldTypeDescription
data[].userIdstringUser ID
data[].roleIdstringRole ID
data[].tenantIdstringTenant ID
data[].assignedAtstringISO timestamp when the role was assigned
data[].assignedBystringUser ID of the person who assigned the role
data[].role.namestringName of the role
data[].role.descriptionstringDescription of the role
data[].role.moduleIdsstring[]Array of module IDs the role has access to

14. Get User’s Module Access

Retrieves a user’s effective module access based on their assigned roles, grouped by service.

GET /users/modules

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant
X-USER-IDYesUser ID to get module access forb1331d7a-a081-70ec-6c9d-a8d96203c377
Example Curl Command
Terminal window
curl --location 'http://localhost:9021/access-roles-service/api/v1/users/modules' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49' \
--header 'X-USER-ID: b1331d7a-a081-70ec-6c9d-a8d96203c377'
Success Response (200 OK)
{
"success": true,
"message": "User modules found",
"data": [
{
"serviceId": "68302e7bb5a0a90fe57f5184",
"serviceName": "Roles and Permissions",
"modules": [
{
"id": "68303804b5a0a90fe57f5185",
"name": "Create Role",
"hasAccess": true
},
{
"id": "683038f3b5a0a90fe57f5187",
"name": "View All Roles",
"hasAccess": true
}
],
"totalModules": 4,
"accessModules": 4,
"noAccessModules": 0,
"permissionsLabel": "4 permissions",
"hasServiceAccess": true
}
]
}
Error Responses

404 Not Found

{
"success": false,
"message": "User not found",
"error": {
"code": "NOT_FOUND",
"message": "User not found"
}
}

15. Search User Tenant Access

Searches for users and retrieves their tenant access information using specific search criteria.

GET /users/search/tenants

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant

Query Parameters

ParameterRequiredTypeDescriptionExample
emailNo*stringSearch by user’s emailcabob21438@hazhab.com
mobileNo*stringSearch by user’s mobile number-
usernameNo*stringSearch by username-
userIdNo*stringSearch by user ID-

*At least one search parameter must be provided

Example Curl Command
Terminal window
curl --location 'http://localhost:9021/access-roles-service/api/v1/users/search/tenants?email=cabob21438@hazhab.com' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
{
"success": true,
"message": "User tenant access retrieved successfully",
"data": {
"userId": "b1331d7a-a081-70ec-6c9d-a8d96203c377",
"totalTenants": 1,
"tenants": [
{
"tenantId": "682581255a53dbe3ffb4fe49",
"tenantName": "Quick Couriers"
}
]
}
}
Error Responses

400 Bad Request

{
"success": false,
"message": "At least one search criteria must be provided (email, mobile, username, or userId)",
"error": {
"code": "BAD_REQUEST",
"message": "At least one search criteria must be provided (email, mobile, username, or userId)"
}
}

404 Not Found

{
"success": false,
"message": "User not found",
"error": {
"code": "NOT_FOUND",
"message": "User not found"
}
}

16. Get User’s Tenant Access

Retrieves all users and their tenant access information for the specified tenant.

GET /users/tenant

Headers

HeaderRequiredDescriptionExample
X-TENANT-IDYesTenant IDtest-tenant
Example Curl Command
Terminal window
curl --location 'http://localhost:9021/access-roles-service/api/v1/users/tenant' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
{
"success": true,
"message": "Users found successfully",
"data": [
{
"_id": "b1331d7a-a081-70ec-6c9d-a8d96203c377",
"name": "Quick Courier Test Admin",
"username": "cabob21438@hazhab.com",
"tenantAccess": [
{
"tenantId": "682581255a53dbe3ffb4fe49",
"accessModules": [],
"role": "user"
}
],
"createdOn": 1747305013996,
"updatedOn": 1747305013996
}
],
"total": 3,
"page": 1,
"limit": 10
}
Error Responses

404 Not Found

{
"success": false,
"message": "Tenant not found",
"error": {
"code": "NOT_FOUND",
"message": "Tenant not found"
}
}

Common Error Responses

View All Common Error Responses

400 Bad Request

{
"success": false,
"message": "Invalid input data",
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid input data"
}
}

404 Not Found

{
"success": false,
"message": "Resource not found",
"error": {
"code": "NOT_FOUND",
"message": "Resource not found"
}
}

409 Conflict

{
"success": false,
"message": "Resource already exists",
"error": {
"code": "CONFLICT",
"message": "Resource already exists"
}
}

503 Service Unavailable

{
"success": false,
"message": "Service unavailable",
"error": {
"code": "SERVICE_UNAVAILABLE",
"message": "Service is currently unavailable"
}
}