# Import integrated account

> Source: https://truto.one/docs/api-reference/admin/integrated-accounts/create/

`POST /integrated-account`

Resource: **Integrated accounts**

## Request body

- **`tenant_id`** _(string)_
  The ID of the tenant.
- **`environment_integration_id`** _(string)_
  The ID of the environment integration (installed integration).
- **`context`** _(object)_
  The context of the integrated account. You can find these in the `Variables` section of an integrated account in the Truto UI. For creating an integrated account with authentication_type `oauth2`, `oauth2_client_credentials` and `keka_oauth`, set the `oauth` object to ``` { "token": { "access_token": "<token_value", "refresh_token": "<if_available>", "expires_in": <value> } } ``` For api_key, please refer the fields section of `credentials` object of the integration.
- **`authentication_method`** _(string)_
  Type of authentication used.
  Allowed: `oauth2`, `oauth`, `api_key`, `oauth2_client_credentials`, `keka_oauth`, `jwt_bearer`, `aws_sts`
- **`region`** _(string)_
  The region where the integrated account is placed.
  Allowed: `wnam`, `enam`, `apac`, `eu`

## Response body

- **`id`** _(string)_
  The ID of the integrated account.
- **`tenant_id`** _(string)_
  The ID of the tenant.
- **`environment_integration_id`** _(string)_
  The ID of the environment integration (installed integration).
- **`context`** _(object)_
  The context of the integrated account. You can find these in the `Variables` section of an integrated account in the Truto UI.
- **`status`** _(string)_
  Status of the integrated account. - `active` - Everything is fine and the account should work - `connecting` - Post install and validation steps are being run - `post_install_error` - There was an error while running post install steps - `validation_error` - There was an error while running validation steps - `needs_reauth` - There was an error while refreshing the credentials in case of OAuth authentication or the credentials are no longer valid in other authentication methods. The integrated account needs to be reauthorized. An account that has been `needs_reauth` for 7 days without changing is **stale**: it keeps this status, and also carries `stale_since`. Truto then stops calling the provider for it. Its unified, proxy, custom, MCP tool and batch calls get a `401` with `truto_error_code: integrated_account_needs_reauth`, and its background token refreshes and scheduled actions pause. Reconnecting the account, a successful token refresh, a change to its credentials or `context`, or setting `status` back to `active` ends the pause within about two minutes. Any other change to the account lifts the pause at the next hourly check, and starts the 7 days again from that change.
  Allowed: `active`, `connecting`, `post_install_error`, `validation_error`, `needs_reauth`
- **`last_error`** _(string)_
  The last error that occurred while running the post install or validation steps.
- **`last_forbidden_error`** _(object)_
  Details of the most recent `403 Forbidden` returned by the third-party API for this account, or `null` if the most recent call succeeded. Cleared automatically on the next successful call.
  - **`resource`** _(string)_
    The third-party resource that was forbidden.
  - **`method`** _(string)_
    The method that was attempted on that resource.
  - **`missing_scopes`** _(array<string>)_
    The scopes required by this resource and method that the provider did not confirm as granted. Present only when both halves of that comparison are known: the provider echoed the scopes it granted, **and** this resource and method declares required scopes. It is **absent** — not empty — otherwise, which includes `api_key` and OAuth1 connections (no scope grant exists), OAuth2 and `jwt_bearer` connections where the provider omits `scope` from its token response, resources and methods that declare no required scopes, and requirements that are not OAuth scopes at all (`refusal_basis: non_scope_requirement` — see `permission_vocabulary`), where no diff is run and `required_permissions` carries the answer instead. An empty array therefore means "no *all-of* scope is missing", while an absent field means "cannot be determined" — two different statements. Read `refusal_basis` for the one question this field cannot answer on its own, "was anything missing at all": an empty array sits beside a populated `missing_any_of_scopes` whenever the whole shortfall is an unmet any-of requirement, so on `refusal_basis: scopes_missing` an empty array does **not** mean every permission was granted. It means that on `refusal_basis: scopes_satisfied`, and only there. Do not default an absent `missing_scopes` to `[]` either: that reads back as "nothing is missing" about a request that was refused. Truto's comparison is an inference over integration configuration. The provider's own account of the refusal is the authoritative one, and Truto relays it without interpreting it: `raw_response` (the error body verbatim) and `message` (its human text) on the 403 itself, and a capped copy of the body on this record as `raw_response_excerpt`. `message` is not persisted, so re-run the call to see it. Truto deliberately does not lift a "code" or a "documentation link" out of that body. Which key in an arbitrary provider's error shape is the important one has no correct general answer, and a confidently wrong one placed above a correct body is the same failure as reporting a scope missing that was never checked.
  - **`refusal_basis`** _(string)_
    Which of the states below produced this record, so a reader never has to infer it from the presence or emptiness of `missing_scopes`. Absent on rows recorded before Truto stored it — and on such a row an empty `missing_scopes` cannot be read as "compared, nothing missing", because it was also written when nothing had been compared at all. **An open set, and `x-extensible-enum` rather than `enum` says so to a code generator as well as to a reader.** Prose asking for a default branch is not something a generator reads, and a closed union here can be violated by design: the read path deliberately accepts an unrecognised value so a row written by a newer build stays readable after a rollback, and the older build then serves that value straight back on this field. The values below are what Truto writes today. Keep a default branch. The live `truto_error_insight.forbidden_error.value.refusal_basis` keeps a closed `enum`, and the asymmetry is the point: a running build always emits its own documented set, while a stored row can carry a value the build reading it never wrote.
  - **`description`** _(string)_
    The sentence the live 403 carried, recorded so this row reads the same as the call did.
  - **`missing_any_of_scopes`** _(array<string>)_
    Scopes of which the operation needs *any one*, where the grant holds none. Kept apart from `missing_scopes` so alternatives are never reported as though all were required.
  - **`required_permissions`** _(array<string>)_
    What this operation requires, whether or not a comparison was possible. Always paired with `permission_vocabulary`, since the same string means "reconnect and grant this", "add this to your API key" or "ask an admin for this role" depending on which vocabulary it is written in.
  - **`required_any_of_permissions`** _(array<string>)_
    Permissions of which the operation needs *any one*, kept apart from `required_permissions` for the same reason.
  - **`permission_vocabulary`** _(string)_
    Which vocabulary `required_permissions` is written in, and therefore what the remedy is. Only `oauth_scope` is fixed by reconnecting: `api_key_permission` is granted to the API key in the provider, and `role_label` in the provider's own admin console. `x-extensible-enum` for the same reason as `refusal_basis` above: this is a stored value, and a rollback can serve one written by a build that knew a fourth vocabulary. Keep a default branch.
  - **`raw_response_excerpt`** _(string)_
    A capped copy of the integration's own error body, so this record shows what the provider said and not only what Truto inferred about it. Truncated with a trailing `… truncated` marker past 2,048 **bytes** of UTF-8, because this record is deserialized on every proxy and unified call that resolves the account and that cost is what the bound exists to control. Bytes, not characters: 2,048 characters of CJK is about 6 KB stored, so a character bound would charge one language three times what it charges another. Expect fewer characters than 2,048 for any non-ASCII body. The 2,048 covers the marker as well, so the stored value never exceeds it. **A truncated excerpt is not parseable.** It is a byte prefix of a serialized body with a marker on the end, so `JSON.parse` on this field throws whenever truncation happened — which the trailing `… truncated` is how you detect. Render it as text. An untruncated excerpt of a JSON body does parse, but nothing guarantees this field is JSON at all: a plain-text or HTML error body is stored exactly as it arrived. Absent when the refusal carried no body. Not forwarded to the connections widget: it is a raw provider string, which is what `connections.show_error_details` exists to keep away from an end user. Note that "every remote 403 carries an insight" and "every remote 403 leaves a record here" are different statements. A Proxy API **custom method** and a **Custom API** both carry the live insight, but a Custom API names no resource or method, and writing `{resource: "", method: ""}` would replace a record naming a real call with one naming none — so no record is written for those. Read the insight on the response for them.
  - **`occurred_at`** _(string)_
    When the forbidden response was recorded.
- **`last_action_run_result`** _(object)_
  The results of the post install and validation steps that ran on the integrated account.
- **`integration_override`** _(object)_
  An optional config override applied for this integrated account only. Deep-merged on top of the integration config and the environment-level override at request time.
- **`unified_model_override`** _(object)_
  Account-scoped unified-mapping overrides, deep-merged on top of the environment and base mappings for this integrated account only.
- **`features`** _(object)_
  Platform features enabled on the integrated account. `super_query` holds the SuperQuery region once a sync job run with SuperQuery has run for the account.
- **`created_at`** _(string)_
  The date and time when the integrated account was created.
- **`updated_at`** _(string)_
  The date and time when the integrated account was last updated.
- **`is_sandbox`** _(boolean)_
  Whether the integrated account is in sandbox mode or not. Sandbox integrated accounts do not allow any "write" operations.
- **`authentication_method`** _(string)_
  Type of authentication used.
  Allowed: `oauth2`, `oauth`, `api_key`, `oauth2_client_credentials`, `keka_oauth`, `jwt_bearer`, `aws_sts`
- **`region`** _(string)_
  The region where the integrated account is placed.
  Allowed: `wnam`, `enam`, `apac`, `eu`
- **`environment_id`** _(string)_
  The ID of the environment this integrated account belongs to.
- **`integration`** _(object)_
  - **`id`** _(string)_
    The ID of the integration.
  - **`name`** _(string)_
    The name of the integration.
  - **`category`** _(string)_
    The category of the integration.
  - **`is_beta`** _(boolean)_
    Whether the integration is in beta or not. Beta integrations might not have been tested completely and are not recommended for production environments.
  - **`config`** _(object, required)_
    The configuration object defining the underlying API of the integration.
    - **`base_url`** _(string)_
      Default base URL prepended to every resource method's `path`.
    - **`label`** _(string)_
      Human-readable name shown in the Truto Dashboard and Link UI.
    - **`logo`** _(string)_
      URL to the integration logo (square, recommended 256x256).
    - **`icon`** _(string)_
      URL to a smaller monochrome icon used in catalog listings.
    - **`headers`** _(object)_
      Default HTTP headers merged into every outbound request. Values may be templated with JSONata placeholders.
    - **`query`** _(object)_
      Default query-string params merged into every outbound request.
    - **`query_array_format`** _(string)_
      Allowed: `comma`, `brackets`, `indices`, `repeat`
    - **`actions`** _(object)_
      Named integration actions. Reserved keys (`post_install`, `post_connect_user_form`, `refresh_token`, `validation`) hook into specific platform lifecycle events; custom names are callable from the proxy/sync runtime.
    - **`credentials`** _(object)_
      Either a single credential definition (when the integration only supports one auth format) or a map keyed by auth format (when an integration supports multiple, e.g. `api_key` and `oauth2`). For multi-format integrations, the customer picks one in the Connect UI. Each credential's `config.label` and `config.help_text` customize the auth-method card shown in the Connect UI. A `jwt_bearer` or `aws_sts` credential must be keyed by its format (`credentials.jwt_bearer`, `credentials.aws_sts`): sent as the single definition, it is refused with a `400`.
    - **`authorization`** _(object)_
      How Truto applies the resolved credential to outbound HTTP requests. The `format` discriminator selects which `config` shape applies. All string values support Truto placeholders (`{{path}}`) resolved against the runtime context. Common placeholder roots: `{{api_key}}` for fields collected at connect time, `{{oauth.token.access_token}}` for OAuth2 access tokens, `{{environment_variables.MY_KEY}}` for env-vars set at the environment-integration level.
      _One of:_
      - **bearer**
        - **`format`** _(string)_
          Allowed: `bearer`
        - **`config`** _(object, required)_
      - **basic**
        - **`format`** _(string)_
          Allowed: `basic`
        - **`config`** _(object)_
      - **header**
        - **`format`** _(string)_
          Allowed: `header`
        - **`config`** _(object)_
    - **`pagination`** _(object)_
      Pagination strategy for an integration or a single resource method. The `format` discriminator selects which `config` shape applies.
      _One of:_
      - **page**
        - **`format`** _(string)_
          Allowed: `page`
        - **`config`** _(object)_
          Page-number pagination options. All fields optional; defaults shown.
      - **cursor**
        - **`format`** _(string)_
          Allowed: `cursor`
        - **`config`** _(object, required)_
          Cursor pagination options.
      - **link_header**
        - **`format`** _(string)_
          Allowed: `link_header`
        - **`config`** _(object)_
      - **offset**
        - **`format`** _(string)_
          Allowed: `offset`
        - **`config`** _(object)_
      - **range**
        - **`format`** _(string)_
          Allowed: `range`
        - **`config`** _(object)_
      - **dynamic**
        - **`format`** _(string)_
          Allowed: `dynamic`
        - **`config`** _(object, required)_
    - **`rate_limit`** _(object)_
      How Truto detects and reacts to upstream rate-limiting. All fields are JSONata expressions evaluated against the upstream response.
      - **`is_rate_limited`** _(string)_
        JSONata expression returning a truthy value when the response should be treated as rate-limited. When omitted, Truto falls back to `status === 429`. Input: `IntegrationRateLimitExpressionContext`. Output: boolean.
      - **`retry_after_header_expression`** _(string)_
        JSONata expression returning the seconds to wait before retrying. When omitted, Truto reads the standard `Retry-After` header. Input: `IntegrationRateLimitExpressionContext`. Output: number (seconds).
      - **`rate_limit_header_expression`** _(string)_
        JSONata expression returning the current rate-limit window state. Truto forwards this as `RateLimit-Limit` / `RateLimit-Remaining` / `RateLimit-Reset` headers in the proxy response. Input: `IntegrationRateLimitExpressionContext`. Output: `IntegrationRateLimitHeaderValues`.
    - **`resources`** _(object)_
      Resource → method tree (e.g. `resources.users.list`). The inner key is one of the canonical methods (`list`, `get`, `create`, `update`, `delete`) or a custom method name. Each method definition matches `IntegrationResourceMethod`.
    - **`tool_tags`** _(object)_
      Optional tag arrays keyed by resource name (`contacts`) or `resource.method` (`contacts.delete`). Method-level tags are unioned with resource-level tags when building MCP tools and filtering by MCP token `config.tags`.
    - **`webhook`** _(object)_
      How Truto receives and verifies inbound webhooks for this integration. **Not** to be confused with `WebhookSchema` elsewhere in this spec, which describes Truto's _outbound_ webhook delivered to your application. An inbound webhook whose body is larger than 1 MiB is refused with a 413.
      - **`signature_verification`** _(object)_
        Strategy used to verify the webhook signature before accepting it. Runs **after** `payload_transform` and **after** `handle_verification` returns `{ type: 'payload' }`.
      - **`handle_verification`** _(string)_
        JSONata expression evaluated on **every** inbound webhook before signature verification. Use to: * Respond to handshake pings (return `{ type: 'verify', verification_response: { status_code, body, headers } }`). * Surface meta-events that should not fan out (return `{ type: 'meta' }`). * Update the integrated account context (return `{ type: 'verify' \| 'payload' \| 'meta', update_context: { ... } }`). * Pass through to fan-out (return `{ type: 'payload' }` or omit entirely — defaults to `payload`). Input: `IntegrationWebhookPayloadContext`. Output: `IntegrationWebhookHandleVerificationResult`.
      - **`payload_transform`** _(string)_
        JSONata expression that transforms the raw inbound payload **before** `handle_verification` and `signature_verification` see it. Use to normalize vendor-specific envelopes (e.g. unwrap a Salesforce `payloads[]` array, decode a base64 body). Input: `IntegrationWebhookPayloadContext`. Output: `IntegrationWebhookPayloadContext` (the same shape — what you return becomes the new payload).
    - **`error_expression`** _(string)_
      Integration-wide JSONata expression evaluated on every response. Use to detect errors in successful (2xx) responses, normalize error messages, or transform "errors" with `< 400` status into successful responses. Overridden by per-method `IntegrationResourceMethod.error_expression` when set. Input: `IntegrationErrorExpressionContext`. Output: `IntegrationErrorExpressionResult` — return `null`/`undefined` to indicate "no error", or a `{ status, message?, headers?, metadata?, result? }` object.
    - **`browser_file_picker_requires_access_token`** _(boolean)_
      This provider's **browser** file picker cannot run without the connected account's upstream `access_token`, so `GET /integrated-account/me` releases `context.oauth.token.access_token` — and nothing else — to a connect-flow integrated account token. Google Drive and Box need it; their picker SDKs take the token client-side. SharePoint, OneDrive and Dropbox authenticate by other means and must leave this unset. A `refresh_token` is never released, whatever this is set to. Honoured only on the integration's own `config`: it is not part of `EnvironmentIntegrationConfig`, and it is stripped from an integrated account's `integration_override`, so it cannot be switched on for a single environment or account.
    - **`use_static_gate`** _(boolean)_
      Send every outbound request and token exchange for this integration through Truto's default Static Gate (fixed-IP proxy, configured on the worker), for vendors that allowlist Truto's IPs. An integrated account's own `context.truto_static_gate_id` takes precedence. If the flag is set but the worker has no gate configured, the request fails instead of going direct. The default gate only forwards to the host of the base integration's `base_url` and of its OAuth token, refresh and revoke URLs, and their subdomains (a placeholder in the host keeps only its static suffix, e.g. `{{x}}.api.gong.io` allows `*.api.gong.io`). A `base_url` or token host set through an override, or any other host, fails the request instead of going direct. OAuth 1.0a token calls cannot be sent through a gate, so an OAuth 1.0a connect on an integration with this flag fails instead of going direct. Only the root team can set, change or clear it, and a config update that omits it keeps the stored value. Honoured only on the integration's own `config`: it is not part of `EnvironmentIntegrationConfig`, and it is stripped from an integrated account's `integration_override`.
    - **`oauth_app_headers`** _(object)_
      Headers built from the connected account's OAuth app and sent on every request, for providers that want the app's own key next to the user's token. Etsy, for example, needs `{ "x-api-key": "{{client.id}}:{{client.secret}}" }`. A value may use `{{client.id}}` and `{{client.secret}}` — the OAuth client the account's token was issued to, read and filled in as the token refresh does — and no other placeholder. Saving an integration fails with a 400 if a value uses any other placeholder, or if a header name is one that debug output echoes back (`x-truto-*`, `content-type`, `accept`, `user-agent` and similar). A header that can't be filled completely is left out: a client field it uses is unset, or is still a placeholder the account's context can't fill. Added after `authorization`, replacing a header of the same name in any letter case. Only accounts connected with `oauth2` get these headers, and a method with `no_auth` doesn't. Honoured only on the integration's own `config`: it is not part of `EnvironmentIntegrationConfig`, and it is stripped from an integrated account's `integration_override`. A header that uses `{{client.secret}}` is sent only to the sites of the requests configured by whoever set that secret: the integration, or an environment's override over it. An environment or account override that keeps that app but sends requests elsewhere (its own `base_url`, a method's URL, an `authorization` expression, a mapping's path) sends them without these headers. Through a Static Gate, the target URL counts. An account's own secret (in its `integration_override`, or filled in from its context) goes wherever its requests go.
  - **`team_id`** _(string)_
    The ID of the team that owns this integration.
  - **`sharing`** _(string)_
    The sharing policy of the integration.
    Allowed: `allow`, `ask`, `deny`
  - **`created_at`** _(string)_
    The date and time when the integration was created.
  - **`updated_at`** _(string)_
    The date and time when the integration was last updated.
- **`object_store_context_fields`** _(array<string>)_
  The list of context fields that are stored in the object store.
- **`stale_since`** _(string)_
  Present only on a stale account: one that has been `needs_reauth` and unchanged for 7 days, so Truto has stopped calling its integration. When Truto found it stale. Returned by `GET /integrated-account` and `GET /integrated-account/{id}`, but not when the list is narrowed with `select`.
- **`delete_after`** _(string)_
  Present only on a stale account once its first deletion reminder has gone out, while automatic deletion of stale accounts is on. Before that reminder the date can still move, so it is not shown, and the `integrated_account:stale` webhook, sent when the account goes stale, never carries it. Truto deletes the account on its first hourly check after this time, and sends `integrated_account:deleted`. The date is 30 days after the account went stale, and never sooner than 15 days after Truto found it stale. Every admin of the team is emailed, and notification destinations subscribed to `integrated_account_events` are told, 15 and 7 days before; a reminder moves an earlier date to the end of the UTC day 15 (or 7) days after it. No account is deleted before both reminders have gone out, so one whose team has no active admin and no such destination is never deleted. An account more than a day past this time, because deletion was not running, gets its 7-day reminder again first, with a new date 7 days on. Reconnect the account to cancel the deletion, or keep it with `POST /integrated-account/{id}/keep`.

## Code examples

### Truto CLI

```bash
truto accounts create \
  -b '{
  "tenant_id": "acme-1",
  "environment_integration_id": "b179ad55-db02-4bd4-b7a4-d2c173eee9ae",
  "context": {
    "oauth": {
      "token": {
        "access_token": "secret_foo_bar",
        "refresh_token": "refresh_foo_bar",
        "expires_in": 3600
      }
    }
  },
  "authentication_method": "oauth2",
  "region": "wnam"
}' \
  -o json
```

### Truto Python SDK

```python
import asyncio
from truto_python_sdk import TrutoApi

truto_api = TrutoApi(token="<your_api_token>")

async def main():
    body = {
        "tenant_id": "acme-1",
        "environment_integration_id": "b179ad55-db02-4bd4-b7a4-d2c173eee9ae",
        "context": {
            "oauth": {
                "token": {
                    "access_token": "secret_foo_bar",
                    "refresh_token": "refresh_foo_bar",
                    "expires_in": 3600
                }
            }
        },
        "authentication_method": "oauth2",
        "region": "wnam"
    }

    result = await truto_api.integrated_accounts._import(body)
    print(result)

asyncio.run(main())
```

### curl

```bash
curl -X POST 'https://api.truto.one/integrated-account' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "tenant_id": "acme-1",
  "environment_integration_id": "b179ad55-db02-4bd4-b7a4-d2c173eee9ae",
  "context": {
    "oauth": {
      "token": {
        "access_token": "secret_foo_bar",
        "refresh_token": "refresh_foo_bar",
        "expires_in": 3600
      }
    }
  },
  "authentication_method": "oauth2",
  "region": "wnam"
}'
```

### JavaScript

```javascript
const body = {
  "tenant_id": "acme-1",
  "environment_integration_id": "b179ad55-db02-4bd4-b7a4-d2c173eee9ae",
  "context": {
    "oauth": {
      "token": {
        "access_token": "secret_foo_bar",
        "refresh_token": "refresh_foo_bar",
        "expires_in": 3600
      }
    }
  },
  "authentication_method": "oauth2",
  "region": "wnam"
};

const response = await fetch('https://api.truto.one/integrated-account', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <your_api_token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

url = "https://api.truto.one/integrated-account"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "tenant_id": "acme-1",
    "environment_integration_id": "b179ad55-db02-4bd4-b7a4-d2c173eee9ae",
    "context": {
        "oauth": {
            "token": {
                "access_token": "secret_foo_bar",
                "refresh_token": "refresh_foo_bar",
                "expires_in": 3600
            }
        }
    },
    "authentication_method": "oauth2",
    "region": "wnam"
}

response = requests.post(url, headers=headers, params=params, json=payload)
print(response.json())
```
