Creates a new API client instance
Initializes the API client with configuration from the ConfigurationManager. The client automatically handles authentication and token refresh.
Optionalconfig: MosaiaConfigOptional configuration object (if not provided, uses ConfigurationManager)
Skip token refresh check to prevent circular dependencies
Makes a GET request to the API
Retrieves data from the specified API endpoint. Supports query parameters for filtering, pagination, and other request options.
API endpoint path (e.g., '/user', '/org', '/agent')
Optionalparams: objectOptional query parameters for filtering and pagination
Promise that resolves to the API response data
Basic GET request:
const users = await client.GET<UserInterface[]>('/user');
const user = await client.GET<UserInterface>('/user/123');
Makes an authenticated GET request that captures a redirect URL instead of following it. Returns the Location header from a 3xx response.
API endpoint path
The redirect URL, or null if the response is not a redirect
Returns the full authenticated URL and headers for a given API path. Useful for endpoints that stream content (e.g. folder ZIP downloads) where the client needs to fetch directly with auth.
API endpoint path
Object with url and headers
Makes a POST request to the API
Creates new resources or performs actions that require data submission. The request body is automatically serialized as JSON.
API endpoint path (e.g., '/user', '/org', '/agent')
Optionaldata: objectRequest body data to be sent
Optionalparams: objectOptional query parameters to append to the URL
Promise that resolves to the API response data
Create a new user:
const newUser = await client.POST<UserInterface>('/user', {
email: 'user@example.com',
first_name: 'John',
last_name: 'Doe'
});
Makes a PUT request to the API
Updates existing resources with new data. The request body is automatically serialized as JSON and sent to the specified endpoint.
API endpoint path (e.g., '/user/123', '/org/456', '/agent/789')
Optionaldata: objectRequest body data for updates
Optionalparams: objectPromise that resolves to the API response data
Update user profile:
const updatedUser = await client.PUT<UserInterface>('/user/123', {
first_name: 'Jane',
last_name: 'Smith',
email: 'jane.smith@example.com'
});
Makes a DELETE request to the API
Removes resources from the system. Supports optional query parameters for additional deletion options like force deletion or soft deletion. Also supports request body for endpoints that require it.
API endpoint path (e.g., '/user/123', '/org/456', '/agent/789')
OptionalbodyOrParams: objectRequest body data (for endpoints that require it) OR query parameters (for backward compatibility)
Optionalparams: objectOptional query parameters (only used when bodyOrParams is a body object)
Promise that resolves to the API response data
Basic deletion:
await client.DELETE<void>('/user/123');
await client.DELETE<void>('/agent/789');
Force deletion with query parameters (backward compatible):
await client.DELETE<void>('/org/456', { force: true });
await client.DELETE<void>('/user/123', {
force: true,
reason: 'account_deletion'
});
Internal API client for making HTTP requests to the Mosaia API
This class provides a centralized HTTP client for all API communication with the Mosaia platform. It handles authentication, request formatting, response processing, and error handling in a consistent manner.
Features:
Remarks
The APIClient uses the ConfigurationManager for settings and automatically handles token refresh when needed. It supports all standard HTTP methods and provides type-safe responses through generics.
Example
Basic usage:
Example
With query parameters:
Example
Error handling: