Skip to main content

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.
id
string
required
Unique identifier for the user
username
string
required
Username used for login
first_name
string
required
User’s first name
last_name
string
required
User’s last name
email
string
required
User’s email address
isActive
boolean
required
Whether the user account is active and can log in
roles
Role[]
Array of roles assigned to the user
permissions
Permission[]
Direct permissions granted to the user
companies
Company[]
Companies the user has access to
employee
Employee[]
Associated employee profile(s)

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

userId
string
required
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

id
number
Role identifier
name
string
Role name (typically uppercase, e.g., “SUPERUSER”, “MANAGER”)
label
string
Human-readable role label
company
Company[]
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

companyId
number
required
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

companyId
number
required
The company ID to fetch locations for

JobTitle

id
number
Job title identifier
name
string
Job title name
description
string
Job title description

Department

id
number
Department identifier
name
string
Department name
address
string
Department address
type
string
Department type
cod_iata
string
IATA code
acronym
string
Department acronym
email
string
Department email

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

message
string
Error message describing the issue
error
string
Error type or code

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

Build docs developers (and LLMs) love