@dichovsky/testrail-api-client
v10.1.0
Published
Type-safe ESM TestRail API client and CLI for Node.js
Maintainers
Readme
TestRail API Client
@dichovsky/testrail-api-client supplies a TypeScript SDK and the testrail CLI for the TestRail REST API.
Use the CLI for shell scripts and CI. Use the SDK for typed application code, shared caching, and request controls.
The package uses ESM and has one runtime dependency: Zod.
Install
The package requires Node.js 26 or newer. CI tests Node 26 on Linux, macOS, and Windows.
npm install @dichovsky/testrail-api-clientSet credentials for either quick start:
export TESTRAIL_BASE_URL="https://your-domain.testrail.io"
export TESTRAIL_EMAIL="[email protected]"
export TESTRAIL_API_KEY="…"Do not put the API key in command arguments or logs. The CLI also accepts the API key through standard input.
Upgrading to 10.1.0
Global user lists now support bounded pagination. The Node.js 26 requirement and the 10.0.0 migration steps stay unchanged.
users.getUsers()and CLIuser liststill return the users from one response. Useusers.getAllUsers()oruser list --allto read all global users within the pagination safety limits.- Use
users.getUsersPage()oruser list --pageto read one global page with its pagination metadata. Requested pages stay limited to 250 items. The client does not support cursor pagination. - Project user reads keep one response.
users.getUsers(projectId)ignores extra runtime arguments, as version10.0.0did. Its TypeScript overload accepts only the project ID. The CLI rejects pagination flags withuser list --project-idbefore authentication.
See SDK pagination and CLI pagination for options and safety limits.
Upgrading to 10.0.0
- Upgrade application, CLI, and CI runtimes to Node.js 26 or newer.
- Remove caller cleanup for file descriptors that you pass to SDK upload methods. Remove this cleanup also for calls that fail before the client sends a request. The SDK now owns those descriptors from the start of the call. See upload ownership.
- Replace
parse()overrides for endpoint responses withonSchemaMismatchfor mismatch reports or strict validation. Apply response transformations after you await the endpoint method. See response validation for affected behavior and examples. - Catch
TestRailApiErrorwithstatus === 0for DNS resolver failures. The client does not throwTestRailValidationErrorfor these failures now. - Pass a
baseUrlwithout a query string or fragment. - Remove
timeout,bodyTimeout,deadlineAt, andcacheVariantfrom objects that you pass toclient.request(). The argument type ofclient.request()does not declare these fields now. Useclient.withTimeout(ms)for a per-request timeout. - Make sure that
typeof result.quality_rating === 'number'is true before you use the field as a number. The field can now be an object of scores. - Expect
TestRailValidationErrorbefore any request for an empty or invalidcase_idsortest_idslist in bulk writes. Expect the same error for an emptyaddCases()array. - Correct CLI scripts that pass one of these arguments, because the command now exits 1:
- A malformed
--limitor--offset. - An empty
--timeout. - A positional argument to
install-skilloruninstall-skill.
- A malformed
The project tests the published declaration files with TypeScript 7. The project does not test other compiler versions. TypeScript is not a runtime or peer dependency of the package. See the changelog for the full release scope and affected methods.
Quick start (SDK)
The example reads a project and then releases the timers and cache of the client:
import { TestRailClient } from '@dichovsky/testrail-api-client';
const client = new TestRailClient({
baseUrl: process.env['TESTRAIL_BASE_URL']!,
email: process.env['TESTRAIL_EMAIL']!,
apiKey: process.env['TESTRAIL_API_KEY']!,
});
try {
const project = await client.projects.getProject(1);
console.log(project.name);
} finally {
client.destroy();
}The SDK supplies compile-time types for write payloads. For dynamic input, call the exported payload schema's .parse(input) before the write.
See the SDK guide for writes, configuration, pagination, and error handling.
Quick start (CLI)
If the package is installed locally, run commands through npx testrail:
npx testrail project list
npx testrail case get 42
# Validate and preview a write without calling TestRail.
npx testrail run add 5 --data '{"name":"CI build","include_all":true}' --dry-run
npx testrail run --helpThe CLI validates write payloads with Zod and prints JSON by default. Remove --dry-run to send the write.
Destructive actions require both --yes and TESTRAIL_ALLOW_DESTRUCTIVE=1.
See the CLI guide for authentication, payload files, output formats, and destructive commands.
Behavior to know
| Topic | Default behavior |
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Lists | A list method returns the items from one response. Use getAll*() or CLI --all for bounded pagination. |
| Responses | Entity-field mismatches are advisory. CLI --strict-responses makes them errors. Paginated lists still validate their outer structure. |
| Caching | The client caches eligible GET responses for five minutes. Dispatched writes clear the cache, with or without an error. Aggregate reads bypass the cache. |
| Retries | Ordinary GET requests retry transient failures. JSON writes and report execution retry only on 429. Uploads never retry. |
| Connections | The client blocks private hosts and redirects. See the networking guide for trusted private servers, proxies, and custom certificates. |
Examine the server state before you retry an uncertain write. A response-validation error can occur after the write executes. The guides below explain limits, exceptions, and configuration.
Documentation
| I want to… | Read | | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Configure the SDK, write data, or handle errors | SDK guide | | Use CLI flags, pagination, or diagnostic files | CLI guide | | Connect through private networks, DNS, or proxies | Networking · DNS · Proxies and certificates | | Find a command or a worked example | Command reference · Recipes | | Find an endpoint or public symbol | API mapping · Symbol index | | Copy a runnable SDK example | Bounded pagination · Publish CI results · Case-field readiness | | Wait for a new custom case field | Case-field readiness | | Install the bundled agent skill | Skill installation | | Understand or contribute to the implementation | Architecture · Contributing · Agent instructions | | Upgrade or publish a release | Changelog · Release guide | | Report a vulnerability | Security policy | | Browse every document | Documentation index |
The client supports TestRail 10.7.0 (Default 1021), including API additions from versions 10.4 through 10.7. The compatibility audit records endpoint coverage, upstream documentation discrepancies, and known gaps against TestRail 10.8 through 10.10.
Sections that moved
Earlier releases documented these topics in this file. Links to the earlier README sections open this table.
| Earlier README section | Current location | | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Repository verification | Verification checks | | Configuration | SDK configuration | | Operation settlement tracking | SDK lifecycle | | Cache isolation and memory | Caching and retries | | Report execution | Caching and retries | | SSRF protection and private hosts | Private servers | | Custom DNS resolvers | Custom DNS resolvers | | Proxies and custom certificate authorities | Proxies and custom certificate authorities | | Pagination | SDK pagination · CLI pagination | | Advisory response validation | Response validation | | Error handling | Error handling | | CLI diagnostic files | Diagnostic files | | Links | Documentation |
License
MIT. If this package saves you time, you can buy me a coffee.
