> ## Documentation Index
> Fetch the complete documentation index at: https://integrations.docs.commenda.io/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK

> Install the Commenda Integrations TypeScript SDK to call the V4 API with full type safety.

The official TypeScript SDK, `@commenda-integrations/api`, is generated from the V4 OpenAPI spec, so every path param, query filter, request body, and response is fully typed.

## Installation

```bash theme={null}
npm i @commenda-integrations/api
```

Import the client:

```ts theme={null}
import { CommendaIntegrations } from "@commenda-integrations/api";
```

## Instantiate the client

Instantiate with your API key (generate keys in the Commenda Dashboard). It targets production by default; pass `baseUrl` to point elsewhere for local development.

```ts theme={null}
const commenda = new CommendaIntegrations({ apiKey: process.env.COMMENDA_API_KEY! });
```

Resources are namespaced: **`commenda.core.*`** for platform & management endpoints, and **`commenda.dataModels.*`** for the unified data models.

## Run your first request

### Core API

```ts theme={null}
// Create an invite link a customer uses to connect their integration
const { data: inviteLink } = await commenda.core.inviteLinks.create({
  integration: "NETSUITE",
  companyName: "Test Company",
});

// List the organisation's companies
const { data: companies } = await commenda.core.companies.list();
```

### Unified API

```ts theme={null}
// List a company's invoices, filtered
const { data: invoices } = await commenda.dataModels.invoices.list(companyId, {
  "status[eq]": "PAID",
  "posted_date[gte]": "2024-01-01",
  limit: 50,
});

// Get one record
const { data: invoice } = await commenda.dataModels.invoices.get(companyId, invoiceId);

// Create (proxied to the connected platform)
await commenda.dataModels.invoices.create(companyId, { data: { /* fields */ } });
```

Iterate every page with the `paginate` helper:

```ts theme={null}
import { paginate } from "@commenda-integrations/api";

for await (const invoice of paginate(next => commenda.dataModels.invoices.list(companyId, { limit: 100, next }))) {
  // ...
}
```

## Error handling

Non-2xx responses throw a `CommendaApiError`:

```ts theme={null}
import { CommendaApiError } from "@commenda-integrations/api";

try {
  await commenda.dataModels.invoices.get(companyId, invoiceId);
} catch (err) {
  if (err instanceof CommendaApiError) {
    console.error(err.statusCode, err.message, err.errorCode, err.requestId);
  }
}
```
