> ## 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.

# Rust SDK

> Get the Rust client, authenticate, and call the API.

The Rust client is the crate `parable-web-api-sdk`. It covers every
operation in the [API reference](https://developers.askparable.com/api-reference/overview.md). Calls are async.

## Get the crate

The Rust client is not in a package registry. Ask your Parable
representative for the crate. The examples on this page also use Tokio:

```toml theme={null}
[dependencies]
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
```

## Import and authenticate

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

```rust theme={null}
use parable_web_api_sdk::{ClientConfig, RequestOptions, WebApiSdk};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let base_url = std::env::var("PARABLE_API_URL")?;
    let token = std::env::var("PARABLE_API_TOKEN")?;
    let workspace = std::env::var("PARABLE_WORKSPACE")?; // for example "acme-corp"

    let sdk = WebApiSdk::new(ClientConfig::with_base_url(base_url, Some(token), None))?;
    let options = RequestOptions::with_header("X-Tenant", workspace, None, None);

    // The Read and Update steps below continue here.

    Ok(())
}
```

The client sends `Authorization: Bearer ...` on every call. Pass
`Some(&options)` to each call to send the `X-Tenant` header.

## Read

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

```rust theme={null}
let me = sdk.users.me(Some(&options)).await?;
println!("{} {}", me.name, me.email);

let connections = sdk
    .vendors
    .tenant_connector_instances(None, Some(&options))
    .await?;
for connection in connections {
    println!("{:?} {:?}", connection.name, connection.connection_status);
}
```

## 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.tenant_connector_taps.tenant_connector_taps(None, Some(&options))`.

```rust theme={null}
use parable_web_api_sdk::types::UpdateTenantConnectorTapInput;

let tap_id = "018f2a3b-9c4d-7e5f-8a6b-1c2d3e4f5a6b".parse()?;
let tap = sdk
    .tenant_connector_taps
    .update_tenant_connector_tap(
        tap_id,
        UpdateTenantConnectorTapInput {
            enabled: Some(false),
            name: None,
            description: None,
            output_schema: None,
            config: None,
            canonical_person_source: None,
        },
        Some(&options),
    )
    .await?;

println!("{:?} {:?}", tap.id, tap.enabled);
```

The update leaves fields set to `None` 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.add_connector_to_tenant`. The Rust client takes the key on
each call, in `EncryptedRequestOptions`. Put your request options in it too,
so that the call names your Workspace:

```rust theme={null}
use parable_web_api_sdk::{EncryptedRequestOptions, PublicEncryptionKey};

let key = sdk.security.encryption_key(Some(&options)).await?;
let encrypted = EncryptedRequestOptions {
    public_encryption_key: Some(PublicEncryptionKey {
        public_key: key.public_key,
        algorithm: key.algorithm.to_string(),
        key_id: key.key_id,
    }),
    request_options: Some(options.clone()),
};

// input is a types::AddConnectorToTenantInput.
let connection = sdk
    .connectors
    .add_connector_to_tenant(input, Some(&encrypted))
    .await?;
```

See [Encrypted request bodies](https://developers.askparable.com/getting-started/encryption.md).

## Handle errors and retries

The client gives each request 30 seconds. Pass a timeout in milliseconds to
`ClientConfig::with_base_url`, or set `timeout_ms` in `RequestOptions` for
one call, to change it. The client does not retry a request.

Each call returns `Result<_, SDKError>`. These methods sort a failure:

| Method | Returns |
| - | - |
| `status_code()` | The HTTP status when the API answered with an error, or `None`. |
| `error_code()` | The error's `code`, such as `WA-PAT-005`, or `None`. |
| `is_auth_denied()` | `true` for `401` and `403`. Fix the token or the roles. Do not retry. |
| `is_transient()` | `true` for a network failure, a timeout, `408`, `429`, and `5xx`. Retry with backoff. |

The variants are `SDKError::Api` (the API answered with an error status),
`SDKError::Network`, `SDKError::Config` (the input failed the client's checks,
or the client is not set up), `SDKError::Request`, `SDKError::Json`, and
`SDKError::Contract`.

```rust theme={null}
match sdk.users.me(Some(&options)).await {
    Ok(me) => println!("{}", me.name),
    Err(err) if err.is_transient() => eprintln!("try again later: {err}"),
    Err(err) => eprintln!("{:?} {:?}: {err}", err.status_code(), err.error_code()),
}
```

> [!TIP]
>
> Each operation page in the [API reference](https://developers.askparable.com/api-reference/overview.md) shows
> the Rust call for that operation. It passes `Some(&options)`, as on this
> page, so that the call sends `X-Tenant`. A call with `None` names no
> Workspace.

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.