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
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID for multi-tenant support | test-tenant |
X-USER-ID | Yes* | User ID for operations | test-user |
Authorization | Yes* | Bearer token for RBAC service | Bearer <token> |
*Required for specific endpoints only
Available Endpoints
Roles Management
- POST
/roles - Create a new role
- GET
/roles - List roles with pagination
- GET
/roles/:id - Get role details
- GET
/roles/:id/modules - Get role’s module access
- PATCH
/roles/:id - Update a role
- DELETE
/roles/:id - Delete a role
- PUT
/roles/:id/users - Assign users to role
- GET
/roles/:id/users - Get users in role
- GET
/roles/:id/users/check - Check user assignments
User Management
- PUT
/users/:userId/roles - Assign roles to a user
- DELETE
/users/:userId/roles - Revoke role from a user
- GET
/users/:userId/roles - Get user’s roles
- GET
/users/modules - Get user’s module access
- GET
/users/search/tenants - Search user tenant access
- GET
/users/tenant - Get all users for a tenant
System Endpoints
- GET
/data/services - Get all services with their modules
- GET
/data/modules - Get all modules
- GET
/health - Health check endpoint
API Endpoints
1. Health Check
Checks the health status of the service and its dependencies.
Example Curl Command
curl --location 'http://localhost:9021/access-roles-service/api/v1/health'
Success Response (200 OK)
"message": "Service is healthy",
"timestamp": "2025-06-04T07:59:17.404Z",
"host": "mongodb+srv://app_dev_user_prayogrbca:****@prayogdevqa.em5uh.mongodb.net/rbca",
"collections": ["Users", "Modules", "Services", "Tenants", "test", "APIKeys", "UserRoles", "APIs", "Roles"]
2. List Roles
Retrieves a paginated list of roles for a tenant.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
Example Curl Command
curl --location 'http://localhost:9021/access-roles-service/api/v1/roles' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
"message": "Roles found",
"_id": "683eb9b6a5c11d9c6556bd69",
"description": "Will manage",
"tenantId": "682581255a53dbe3ffb4fe49",
"_id": "683eb949a5c11d9c6556bd57",
"description": "Will operator all bookings",
"tenantId": "682581255a53dbe3ffb4fe49",
"moduleIds": ["68303804b5a0a90fe57f5185", "683038f3b5a0a90fe57f5187"],
3. Create Role
Creates a new role in the specified tenant.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
X-USER-ID | Yes | User ID for audit tracking | test-user |
Content-Type | Yes | Must be application/json | application/json |
Request Body
"description": "Administrator role with full access",
"moduleIds": ["module1", "module2"]
Example Curl Command
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' \
"description": "Administrator role with full access",
"moduleIds": ["module1", "module2"]
Success Response (201 Created)
"message": "Role created successfully",
"id": "683833bb76b2421e19398860",
"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
"message": "Validation failed",
"code": "VALIDATION_ERROR",
"message": "Invalid input data"
409 Conflict
"message": "A role with this name already exists for this tenant",
"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.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
Path Parameters
| Parameter | Type | Description | Example |
|---|
id | string | Role ID | 683833bb76b2421e19398860 |
Example Curl Command
curl --location 'http://localhost:9021/access-roles-service/api/v1/roles/683eb9b6a5c11d9c6556bd69' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
"_id": "683eb9b6a5c11d9c6556bd69",
"description": "Will manage",
"tenantId": "682581255a53dbe3ffb4fe49",
Error Responses
404 Not Found
"message": "Role not found",
"message": "Role not found"
5. Get Role Module Access
Retrieves the modules accessible to a role, grouped by service.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
Authorization | Yes | Bearer token | Bearer <token> |
Path Parameters
| Parameter | Type | Description | Example |
|---|
id | string | Role ID | 683833bb76b2421e19398860 |
Example Curl Command
curl --location 'http://localhost:9021/access-roles-service/api/v1/roles/683eb949a5c11d9c6556bd57/modules' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
"message": "Role modules found",
"serviceId": "68302e7bb5a0a90fe57f5184",
"serviceName": "Roles and Permissions",
"id": "68303804b5a0a90fe57f5185",
"id": "683038f3b5a0a90fe57f5187",
"name": "View All Roles",
"permissionsLabel": "4 permissions",
Error Responses
404 Not Found
"message": "Role not found",
"message": "Role not found"
6. Update Role
Updates an existing role’s details.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
X-USER-ID | Yes | User ID for audit tracking | test-user |
Content-Type | Yes | Must be application/json | application/json |
Path Parameters
| Parameter | Type | Description | Example |
|---|
id | string | Role ID | 683833bb76b2421e19398860 |
Request Body
"name": "Manager Updated",
"description": "Updated description for Manager"
Example Curl Command
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' \
"name": "Manager Updated",
"description": "Updated description for Manager"
Success Response (200 OK)
"message": "Role updated successfully",
"_id": "683eb9b6a5c11d9c6556bd69",
"name": "Manager Updated",
"description": "Updated description for Manager",
"tenantId": "682581255a53dbe3ffb4fe49",
Error Responses
404 Not Found
"message": "Role not found",
"message": "Role not found"
409 Conflict
"message": "A role with this name already exists for this tenant",
"code": "ROLE_ALREADY_EXISTS",
"message": "A role with this name already exists for this tenant"
7. Delete Role
Deletes a role from the system.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
X-USER-ID | Yes | User ID for audit tracking | test-user |
Path Parameters
| Parameter | Type | Description | Example |
|---|
id | string | Role ID | 683833bb76b2421e19398860 |
Example Curl Command
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)
"message": "Role deleted successfully",
Error Responses
404 Not Found
"message": "Role not found",
"message": "Role not found"
8. Assign Users to Role
Assigns users to a specific role.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
X-USER-ID | Yes | User ID for audit tracking | test-user |
Authorization | Yes | Bearer token | Bearer <token> |
Content-Type | Yes | Must be application/json | application/json |
Path Parameters
| Parameter | Type | Description | Example |
|---|
id | string | Role ID | 683833bb76b2421e19398860 |
Request Body
Example Curl Command
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)
"message": "Users assigned to role successfully",
Error Responses
404 Not Found
"message": "Role not found",
"message": "Role not found"
9. Get Users in Role
Retrieves all users assigned to a specific role.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
Path Parameters
| Parameter | Type | Description | Example |
|---|
id | string | Role ID | 683833bb76b2421e19398860 |
Example Curl Command
curl --location 'http://localhost:9021/access-roles-service/api/v1/roles/683eb949a5c11d9c6556bd57/users' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
"message": "Users for role found successfully",
"_id": "51f32d0a-1011-7066-d410-60fe56133550",
"username": "mockuser22@yopmail.com",
"assignedAt": "2025-06-03T09:11:50.417Z",
"assignedBy": "b1331d7a-a081-70ec-6c9d-a8d96203c377",
"tenantId": "682581255a53dbe3ffb4fe49",
Response Fields
| Field | Type | Description |
|---|
data[]._id | string | User ID |
data[].name | string | User’s full name |
data[].username | string | User’s email/username |
data[].assignedAt | string | ISO timestamp when the user was assigned to the role |
data[].assignedBy | string | User ID of the person who assigned the role |
data[].tenantId | string | Tenant ID the user belongs to |
data[].isAssigned | boolean | Whether the user is assigned to the role |
total | number | Total number of users found |
page | number | Current page number |
limit | number | Number of items per page |
Error Responses
404 Not Found
"message": "Role 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
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | 682581255a53dbe3ffb4fe49 |
Path Parameters
| Parameter | Type | Description | Example |
|---|
id | string | Role ID | 683eb949a5c11d9c6556bd57 |
Query Parameters
| Parameter | Required | Type | Description | Default |
|---|
search | No | string | Search term for filtering users by name or username | - |
page | No | integer | Page number | 1 |
limit | No | integer | Items per page | 10 |
Example Curl Command
curl --location 'http://localhost:9021/access-roles-service/api/v1/roles/683eb949a5c11d9c6556bd57/users/check' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
"message": "Users for role found successfully",
"_id": "51f32d0a-1011-7066-d410-60fe56133550",
"username": "mockuser22@yopmail.com",
"tenantId": "682581255a53dbe3ffb4fe49",
"assignedAt": "2025-06-03T09:11:50.417Z",
"assignedBy": "b1331d7a-a081-70ec-6c9d-a8d96203c377"
Response Fields
| Field | Type | Description |
|---|
data[]._id | string | User ID |
data[].name | string | User’s full name |
data[].username | string | User’s email/username |
data[].tenantId | string | Tenant ID the user belongs to |
data[].isAssigned | boolean | Whether the user is assigned to the role |
data[].assignedAt | string | ISO timestamp when the user was assigned to the role |
data[].assignedBy | string | User ID of the person who assigned the role |
total | number | Total number of users found |
page | number | Current page number |
limit | number | Number of items per page |
11. Assign Roles to User
Assigns one or more roles to a user within a specific tenant context.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
Authorization | Yes | Bearer token | Bearer <token> |
Content-Type | Yes | Must be application/json | application/json |
Path Parameters
| Parameter | Type | Description | Example |
|---|
userId | string | User ID to assign roles to | b1331d7a-a081-70ec-6c9d-a8d96203c377 |
Request Body
"roleId": "683eb9b6a5c11d9c6556bd69"
Example Curl Command
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' \
"roleId": "683eb9b6a5c11d9c6556bd69"
Success Response (200 OK)
"message": "Role assigned successfully",
Error Responses
404 Not Found
"message": "User or role 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
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
Authorization | Yes | Bearer token | Bearer <token> |
Content-Type | Yes | Must be application/json | application/json |
Path Parameters
| Parameter | Type | Description | Example |
|---|
userId | string | User ID to revoke role from | b1331d7a-a081-70ec-6c9d-a8d96203c377 |
Request Body
"roleId": "683eb9b6a5c11d9c6556bd69"
Example Curl Command
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' \
"roleId": "683eb9b6a5c11d9c6556bd69"
Success Response (200 OK)
"message": "Role revoked successfully",
Error Responses
404 Not Found
"message": "User or role 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.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | 682581255a53dbe3ffb4fe49 |
Path Parameters
| Parameter | Type | Description | Example |
|---|
userId | string | User ID to get roles for | 51f32d0a-1011-7066-d410-60fe56133550 |
Query Parameters
| Parameter | Required | Type | Description | Default |
|---|
tenantId | No | string | Filter roles by tenant ID | - |
Example Curl Command
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)
"message": "User roles found",
"userId": "51f32d0a-1011-7066-d410-60fe56133550",
"roleId": "683eb949a5c11d9c6556bd57",
"tenantId": "682581255a53dbe3ffb4fe49",
"assignedAt": "2025-06-03T09:11:50.417Z",
"assignedBy": "b1331d7a-a081-70ec-6c9d-a8d96203c377",
"description": "Will operator all bokings",
"68303804b5a0a90fe57f5185",
"683038f3b5a0a90fe57f5187"
Response Fields
| Field | Type | Description |
|---|
data[].userId | string | User ID |
data[].roleId | string | Role ID |
data[].tenantId | string | Tenant ID |
data[].assignedAt | string | ISO timestamp when the role was assigned |
data[].assignedBy | string | User ID of the person who assigned the role |
data[].role.name | string | Name of the role |
data[].role.description | string | Description of the role |
data[].role.moduleIds | string[] | 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.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
X-USER-ID | Yes | User ID to get module access for | b1331d7a-a081-70ec-6c9d-a8d96203c377 |
Example Curl Command
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)
"message": "User modules found",
"serviceId": "68302e7bb5a0a90fe57f5184",
"serviceName": "Roles and Permissions",
"id": "68303804b5a0a90fe57f5185",
"id": "683038f3b5a0a90fe57f5187",
"name": "View All Roles",
"permissionsLabel": "4 permissions",
Error Responses
404 Not Found
"message": "User 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
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
Query Parameters
| Parameter | Required | Type | Description | Example |
|---|
email | No* | string | Search by user’s email | cabob21438@hazhab.com |
mobile | No* | string | Search by user’s mobile number | - |
username | No* | string | Search by username | - |
userId | No* | string | Search by user ID | - |
*At least one search parameter must be provided
Example Curl Command
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)
"message": "User tenant access retrieved successfully",
"userId": "b1331d7a-a081-70ec-6c9d-a8d96203c377",
"tenantId": "682581255a53dbe3ffb4fe49",
"tenantName": "Quick Couriers"
Error Responses
400 Bad Request
"message": "At least one search criteria must be provided (email, mobile, username, or userId)",
"message": "At least one search criteria must be provided (email, mobile, username, or userId)"
404 Not Found
"message": "User not found",
"message": "User not found"
16. Get User’s Tenant Access
Retrieves all users and their tenant access information for the specified tenant.
| Header | Required | Description | Example |
|---|
X-TENANT-ID | Yes | Tenant ID | test-tenant |
Example Curl Command
curl --location 'http://localhost:9021/access-roles-service/api/v1/users/tenant' \
--header 'X-TENANT-ID: 682581255a53dbe3ffb4fe49'
Success Response (200 OK)
"message": "Users found successfully",
"_id": "b1331d7a-a081-70ec-6c9d-a8d96203c377",
"name": "Quick Courier Test Admin",
"username": "cabob21438@hazhab.com",
"tenantId": "682581255a53dbe3ffb4fe49",
"createdOn": 1747305013996,
"updatedOn": 1747305013996
Error Responses
404 Not Found
"message": "Tenant not found",
"message": "Tenant not found"
Common Error Responses
View All Common Error Responses
400 Bad Request
"message": "Invalid input data",
"code": "VALIDATION_ERROR",
"message": "Invalid input data"
404 Not Found
"message": "Resource not found",
"message": "Resource not found"
409 Conflict
"message": "Resource already exists",
"message": "Resource already exists"
503 Service Unavailable
"message": "Service unavailable",
"code": "SERVICE_UNAVAILABLE",
"message": "Service is currently unavailable"