Overview
The Users API allows you to manage user accounts, roles, permissions, and associated employee profiles. All endpoints require authentication.
User Object
The User type represents a system user with authentication and authorization information.
Unique identifier for the user
Whether the user account is active and can log in
Array of roles assigned to the user
Role name (e.g., “SUPERUSER”, “ADMIN”, “USER”)
Human-readable role label
Permissions granted by this role
Direct permissions granted to the userShow Permission properties
Human-readable permission label
Modules where this permission applies
Companies the user has access to
Associated employee profile(s)
Employee’s middle name (optional)
Employee’s second last name (optional)
Type of identification document
List Users
Retrieve a list of all users in the system.
import axios from '@/lib/axios';
import { User } from '@/types';
const fetchUsers = async (): Promise<User[]> => {
const response = await axios.get('/users');
return response.data.users;
};
Response
{
"users": [
{
"id": "1",
"username": "jdoe",
"first_name": "John",
"last_name": "Doe",
"email": "[email protected]",
"isActive": true,
"roles": [
{
"id": 1,
"name": "ADMIN",
"label": "Administrator",
"permissions": []
}
],
"permissions": [],
"companies": [
{
"id": 1,
"name": "SIGEAC Airlines",
"slug": "sigeac-airlines"
}
],
"employee": []
}
]
}
Get Current User
Retrieve the authenticated user’s profile.
const fetchCurrentUser = async (): Promise<User> => {
const { data } = await axios.get<User>('/user');
return data;
};
Response
Returns a single User object with complete profile information.
Get User by ID
Retrieve a specific user by their ID.
const fetchUserById = async (userId: string): Promise<User> => {
const { data } = await axios.get(`/users/${userId}`);
return data;
};
Parameters
The unique identifier of the user
Roles and Permissions
Get Roles
Retrieve available roles in the system.
const fetchRoles = async (): Promise<Role[]> => {
const { data } = await axios.get('/roles');
return data;
};
Role Object
Role name (typically uppercase, e.g., “SUPERUSER”, “MANAGER”)
Human-readable role label
Companies where this role is available
Get Permissions
Retrieve all available permissions.
const fetchPermissions = async (): Promise<Permission[]> => {
const { data } = await axios.get('/permissions');
return data;
};
Get Permissions by Company
Retrieve permissions for a specific company.
const fetchPermissionsByCompany = async (companyId: number): Promise<Permission[]> => {
const { data } = await axios.get(`/companies/${companyId}/permissions`);
return data;
};
Parameters
The company ID to fetch permissions for
User Locations
Get locations accessible to a user within a specific company.
const fetchUserLocations = async (companyId: number): Promise<Location[]> => {
const { data } = await axios.get(`/companies/${companyId}/user-locations`);
return data;
};
Parameters
The company ID to fetch locations for
JobTitle
Department
Examples
Check User Permissions
const hasPermission = (user: User, permissionName: string): boolean => {
// Check direct permissions
const directPermission = user.permissions?.some(
(p) => p.name === permissionName
);
// Check role permissions
const rolePermission = user.roles?.some((role) =>
role.permissions?.some((p) => p.name === permissionName)
);
return directPermission || rolePermission;
};
Check if User is SuperUser
const isSuperUser = (user: User): boolean => {
return user.roles?.some((role) => role.name === 'SUPERUSER') ?? false;
};
Get User Display Name
const getUserDisplayName = (user: User): string => {
return `${user.first_name} ${user.last_name}`;
};
Filter Active Users
const getActiveUsers = (users: User[]): User[] => {
return users.filter((user) => user.isActive);
};
Error Handling
Error message describing the issue
Common Errors
- 401 Unauthorized: Authentication token is missing or invalid
- 403 Forbidden: User doesn’t have permission to access this resource
- 404 Not Found: User with the specified ID doesn’t exist
- 422 Unprocessable Entity: Invalid data provided