> ## Documentation Index
> Fetch the complete documentation index at: https://developers.askparable.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK

> Install the TypeScript client, authenticate, and call the API.

The TypeScript client is `@parable-platform/web-api-sdk`. It covers every
operation in the [API reference](https://developers.askparable.com/api-reference/overview.md).

## Install

The package is in a private npm registry. Ask your Parable representative
for access. Then install the client and its types:

```bash theme={null}
npm install @parable-platform/web-api-sdk @parable-platform/web-api-types
```

The package contains TypeScript source, not compiled JavaScript. Run it with
Bun, or build it with a bundler.

## Import and authenticate

Create a client with the base URL, your token, and your Workspace. See
[Authentication](https://developers.askparable.com/getting-started/authentication.md) to get a token.

```typescript theme={null}
import { WebApiSDK } from "@parable-platform/web-api-sdk";

const baseUrl = process.env.PARABLE_API_URL;
const token = process.env.PARABLE_API_TOKEN;
const workspace = process.env.PARABLE_WORKSPACE; // for example "acme-corp"
if (!baseUrl || !token || !workspace) {
  throw new Error("Set PARABLE_API_URL, PARABLE_API_TOKEN, and PARABLE_WORKSPACE");
}

const sdk = new WebApiSDK({
  baseUrl,
  auth: { token },
  requestInterceptor: (config) => ({
    ...config,
    headers: { ...config.headers, "X-Tenant": workspace },
  }),
});
```

The client sends `Authorization: Bearer ...` on every call. The
`requestInterceptor` adds the `X-Tenant` header.

## Read

Read your membership, then the Provider connections in your Workspace:

```typescript theme={null}
const me = await sdk.users.me();
console.log(me.name, me.email);

const connections = await sdk.vendors.tenantConnectorInstances();
for (const connection of connections) {
  console.log(connection.name, connection.connectionStatus);
}
```

## Update

Stop a Tap. This call needs a Parable token, because an MCP token only
reads. Replace the ID with one from your Workspace. List Taps with
`sdk.tenantConnectorTaps.tenantConnectorTaps()`.

```typescript theme={null}
const tap = await sdk.tenantConnectorTaps.updateTenantConnectorTap(
  "018f2a3b-9c4d-7e5f-8a6b-1c2d3e4f5a6b",
  { enabled: false },
);

console.log(tap.id, tap.enabled);
```

The update leaves omitted fields unchanged. `enabled: false` stops the Tap.
`enabled: true` does not add a Tap that the connection's `enabledTaps`
leaves out. To turn on an opt-in Tap, see
[Turn Taps on and off](https://developers.askparable.com/connectors/taps.md#turn-taps-on-and-off).

## Encrypt credentials

Two operations take an encrypted body, such as
`sdk.connectors.addConnectorToTenant()`. Get your Workspace's public key and
give it to the client once. The client then encrypts the body of each of
these operations:

```typescript theme={null}
const key = await sdk.security.encryptionKey();
sdk.setPublicEncryptionKey(key);
```

You can also pass the key when you create the client, as
`encryption: { publicEncryptionKey: key }`, or to one call, as
`{ publicEncryptionKey: key }` in its options. See
[Encrypted request bodies](https://developers.askparable.com/getting-started/encryption.md).

## Handle errors and retries

The client gives each request 30 seconds. Set `timeout` in milliseconds when
you create the client to change it. `0` turns the time limit off. The client
does not retry a request.

Each failure is an instance of one of these classes:

| Class | When | Useful fields |
| - | - | - |
| `ApiError` | The API answered with an error status. | `statusCode`, `code`, `requestId`, `message`, `validationErrors` |
| `AuthenticationError` | `401`. A subclass of `ApiError`. | As `ApiError` |
| `AuthorizationError` | `403`. A subclass of `ApiError`. | As `ApiError` |
| `RateLimitError` | `429`. A subclass of `ApiError`. | `retryAfter`, the seconds to wait, or `null` |
| `ValidationError` | The input failed the client's checks. Nothing was sent. | `errors`, `getAllMessages()` |
| `NetworkError` | No answer arrived, or the time limit ended the request. | `message` |

```typescript theme={null}
import { ApiError, NetworkError, RateLimitError } from "@parable-platform/web-api-sdk";

async function withRetry<T>(call: () => Promise<T>, attempts = 3): Promise<T> {
  for (let attempt = 1; ; attempt++) {
    try {
      return await call();
    } catch (error) {
      const retryable =
        error instanceof RateLimitError ||
        error instanceof NetworkError ||
        (error instanceof ApiError && error.statusCode >= 500);
      if (!retryable || attempt === attempts) {
        if (error instanceof ApiError) {
          console.error(error.statusCode, error.code, error.requestId, error.message);
        }
        throw error;
      }
      const seconds = error instanceof RateLimitError && error.retryAfter ? error.retryAfter : 2 ** attempt;
      await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
    }
  }
}

const me = await withRetry(() => sdk.users.me());
```

Retry only a read, or a call that you made safe to repeat, such as a
connection with an `idempotencyKey`.

## Check permissions before a call

`@parable-platform/web-api-sdk/permissions` exports `operationPermissions`.
It maps each operation, by its `namespace.method` name, to the permissions
that admit it. A caller who holds one of them is admitted. A permission also
admits each permission under it: `tenant.connectors` admits
`tenant.connectors.create`. An empty list means that the operation checks no
permission. The module imports nothing, so it does not load the client.

```typescript theme={null}
import { operationPermissions } from "@parable-platform/web-api-sdk/permissions";

const me = await sdk.users.me();
const held = me.roles.flatMap((role) => role.permissions);
const admits = (needed: string) =>
  held.some((permission) => needed === permission || needed.startsWith(`${permission}.`));

const required: readonly string[] = operationPermissions["connectors.addConnectorToTenant"];
const canConnect = required.length === 0 || required.some(admits);
```

Use it to show a control only when the API would accept the call. The API
still checks every request.

> [!TIP]
>
> Each operation page in the [API reference](https://developers.askparable.com/api-reference/overview.md) shows
> the TypeScript call for that operation, such as `sdk.users.me()`.

For table data, use SQL. See [Parable Data Engine](https://developers.askparable.com/data.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.