Grexx Platform API TypeScript Client
The `grexx-api` package provides a strongly-typed TypeScript client for interacting with the Grexx Platform API, which is generated from an OpenAPI 3.0.2 specification. It enables developers to manage various Grexx platform entities such as cases, datasets, forms, and tasks programmatically. This client abstracts the HTTP request details, offering a more intuitive and type-safe interface for API operations. As of version 13.6.2, it is actively maintained, with new releases typically aligning with updates to the underlying Grexx Platform API or improvements in the OpenAPI generator itself. Its primary differentiator is the full TypeScript support, ensuring compile-time safety and a better development experience compared to direct HTTP requests.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'caseInfo')
cause The `CaseService` or other service client was not correctly imported or `grexx-api` itself failed to load.fixEnsure `import { CaseService } from 'grexx-api';` is at the top of your file and that `grexx-api` is correctly installed via `npm install grexx-api`. -
Error: Request failed with status code 401 (Unauthorized)
cause The provided `OpenAPI.TOKEN` is either missing, invalid, or has expired, preventing authentication with the Grexx Platform API.fixVerify that `OpenAPI.TOKEN` is set correctly with a valid, unexpired API key for your Grexx instance. Check the API key's permissions on the Grexx platform. -
Error: Request failed with status code 404 (Not Found)
cause The `OpenAPI.BASE` URL is incorrect, the specific API endpoint does not exist at the provided path, or the resource (e.g., `casePath`) does not exist on the Grexx platform.fixDouble-check `OpenAPI.BASE` against your Grexx platform's API documentation. Confirm that the `casePath` or other resource identifiers are correct and exist on your Grexx instance.
Warnings
- breaking Major version updates (e.g., v12 to v13) typically introduce breaking changes, which directly correspond to significant updates or refactorings in the underlying Grexx Platform API's OpenAPI specification. These changes may include altered endpoint paths, renamed parameters, different response body structures, or changes in required authentication schemes.
- gotcha The `OpenAPI.TOKEN` and `OpenAPI.BASE` configurations are global. If you are developing a server-side application that needs to interact with multiple Grexx instances or different user contexts, direct modification of these global properties can lead to race conditions or incorrect API calls. Ensure these are set appropriately for the current request context.
- gotcha API keys (OpenAPI.TOKEN) and base URLs (OpenAPI.BASE) should never be hardcoded directly into production application code or committed to version control. This is a significant security risk.
Install
-
npm install grexx-api -
yarn add grexx-api -
pnpm add grexx-api
Imports
- OpenAPI
const OpenAPI = require('grexx-api').OpenAPI;import { OpenAPI } from 'grexx-api'; - CaseService
const CaseService = require('grexx-api').CaseService;import { CaseService } from 'grexx-api'; - CaseInfo
import { CaseInfo } from 'grexx-api';import type { CaseInfo } from 'grexx-api';
Quickstart
import { OpenAPI, CaseService } from 'grexx-api';
// Configure the API client with your base URL and API key
OpenAPI.BASE = process.env.GREXX_API_BASE_URL ?? 'https://name.grexx.today/api/v1';
OpenAPI.TOKEN = process.env.GREXX_API_KEY ?? 'your-api-key'; // Replace with a secure way to load your API key
const casePath = 'example-case-id'; // Replace with a valid case ID from your Grexx platform
CaseService.caseInfo(casePath, { css: true, rootline: false })
.then(response => {
console.log('Successfully fetched Case Info:');
console.log(`Case ID: ${response.id}`);
console.log(`Case Title: ${response.title}`);
})
.catch(error => {
console.error('Error fetching case info:', error.message || error);
if (error.status) {
console.error(`Status: ${error.status}, Body: ${JSON.stringify(error.body)}`);
}
});