@shadmanZero/tenantos-api
    Preparing search index...

    Class TenantosClient

    Main TenantOS API client with comprehensive error handling and retry logic

    The TenantosClient class is the primary entry point for interacting with the TenantOS API. It provides a unified interface for all API operations, including server management, network device configuration, user administration, and system monitoring.

    Features:

    • Type Safety: Full TypeScript support with comprehensive type definitions
    • Error Handling: Custom error classes with detailed error information
    • Retry Logic: Automatic retry for transient failures with configurable backoff
    • Request Logging: Optional debug logging for requests and responses
    • Resource Organization: Logical grouping of API endpoints into resource classes
    • Validation: Input validation for all parameters
    • Immutable Config: Configuration is frozen after client creation for safety
    const client = new TenantosClient({
    baseUrl: 'https://your-tenant.tenantos.com',
    apiKey: 'your-api-key'
    });

    // List all servers
    const servers = await client.servers.list();

    // Get a specific server
    const server = await client.servers.get(123);

    // Create a new server
    const newServer = await client.servers.create({
    hostname: 'new-server.example.com',
    servername: 'New Server',
    // ... other properties
    });
    const client = new TenantosClient({
    baseUrl: 'https://your-tenant.tenantos.com',
    apiKey: 'your-api-key',
    timeout: 60000,
    debug: true,
    retry: {
    attempts: 5,
    delay: 2000
    },
    headers: {
    'X-Custom-Header': 'custom-value'
    }
    });
    try {
    const server = await client.servers.get(999);
    } catch (error) {
    if (isTenantosApiError(error)) {
    console.log(`API Error: ${error.statusCode} - ${error.message}`);
    if (error.isNotFound()) {
    console.log('Server not found');
    }
    }
    }
    Index

    Constructors

    • Creates a new TenantOS API client instance

      The constructor validates the provided configuration, sets up the HTTP client with appropriate defaults, configures request/response interceptors, and initializes all resource instances for API operations.

      Parameters

      Returns TenantosClient

      When configuration validation fails

      const client = new TenantosClient({
      baseUrl: 'https://your-tenant.tenantos.com',
      apiKey: 'your-api-key-here',
      timeout: 30000,
      debug: false
      });

    Properties

    aliasRoles: AliasRolesResource
    aliasUsers: AliasUsersResource
    brands: BrandsResource
    externalProviders: ExternalProvidersResource
    files: FilesResource
    inventoryComponents: InventoryComponentsResource
    ipManagement: IPManagementResource
    networkDevices: NetworkDevicesResource
    pxeDisklayouts: PXEDisklayoutsResource
    pxeProfiles: PXEProfilesResource
    pxeScripts: PXEScriptsResource
    pxeWindows: PXEWindowsResource
    remoteAgents: RemoteAgentsResource
    servers: ServersResource

    Methods

    • Get the client configuration (readonly)

      Returns a readonly copy of the client configuration that was provided during client initialization. This can be useful for debugging or logging purposes.

      Returns Readonly<TenantosClientConfig>

      Readonly copy of the client configuration

      const config = client.getConfig();
      console.log(`Base URL: ${config.baseUrl}`);
      console.log(`Debug mode: ${config.debug}`);
    • Get available system timezones

      Retrieves a list of all available timezones that can be used for system configuration and scheduling operations.

      Returns Promise<string[]>

      Promise that resolves to an array of timezone strings

      If the request fails

      const timezones = await client.getSystemTimezones();
      console.log('Available timezones:', timezones);
    • Get system version information

      Retrieves version information about the TenantOS system, including the current software version and build information.

      Returns Promise<SystemVersion>

      Promise that resolves to system version information

      If the request fails

      const version = await client.getSystemVersion();
      console.log(`TenantOS version: ${version.version}`);
    • Test API connectivity and authentication

      Performs a simple ping request to verify that the client can successfully connect to the TenantOS API and that the provided authentication credentials are valid.

      Returns Promise<boolean>

      Promise that resolves to true if connection is successful, false otherwise

      const isConnected = await client.ping();
      if (isConnected) {
      console.log('Successfully connected to TenantOS API');
      } else {
      console.log('Failed to connect to TenantOS API');
      }
    • Make a raw request to the API with automatic retry logic

      This is the core method that handles all HTTP requests to the TenantOS API. It includes automatic retry logic for transient failures, comprehensive error handling, and request/response logging when debug mode is enabled.

      The method will automatically retry requests that fail due to:

      • Network connectivity issues
      • Server errors (5xx status codes)
      • Rate limiting (429 status code)

      Type Parameters

      • T

        The expected type of the response data

      Parameters

      • config: RequestConfig

        Request configuration including method, URL, data, and parameters

      Returns Promise<ApiResponse<T>>

      Promise that resolves to the API response

      For API-related errors (4xx, 5xx responses)

      For network connectivity issues

      For request timeouts

      // Make a GET request
      const response = await client.request<Server>({
      method: 'GET',
      url: '/api/servers/123'
      });

      // Make a POST request with data
      const response = await client.request<Server>({
      method: 'POST',
      url: '/api/servers',
      data: {
      hostname: 'new-server.example.com',
      servername: 'New Server'
      }
      });