Create link token
/link-token
Link tokens allow your customers to connect their apps with Truto. Link tokens are used to initiate a connection flow handled by Truto and the end of this connection flow, an Integrated Account is created. This integrated account acts as a link between your Truto account and the app your customer has connected.
To create a link token, you need to specify a tenant_id in the request body. tenant_id references a Tenant — an environment-scoped external identity (your customer, workspace, or organisation) that owns one or more integrated accounts.
Truto auto-creates the tenant when an integrated account is first created with a given tenant_id (as long as the id can be carried in a URL path segment — see Tenants). Creating a link token alone does not materialize the tenant — the row appears after a successful connection (or a direct POST /integrated-account). If you'd rather attach metadata (tier, region, billing plan) before the customer connects, pre-create the tenant with POST /tenant first and use the same id here.
::: tip
One tenant can own multiple integrated accounts. For example, one of your customers could connect HubSpot, Salesforce, and Slack — all under the same tenant_id — and you can list every account for that customer with a single GET /integrated-account?tenant_id=... call.
:::
Reauthorizing an integrated account
An integrated account can be reauthorized by creating a link token for it. Instead of tenant_id, you need to specify the id of the integrated account you need to reauthorize as the integrated_account_id attribute in the request body. Do NOT specify tenant_id.
You can use it similar to other link tokens, with the only difference being that the customer will automatically land on the specific integration's page in Truto's connection UI and will be asked to proceed with connecting the application. After the connection flow completes, the new credentials will be updated in the integrated account.
Custom OAuth Scopes
You can specify custom OAuth scopes using the scopes field for both new integrated accounts and when reauthorizing existing ones. These scopes will take precedence over any unified model scopes or integration default scopes during the OAuth flow. This is useful when you need to request additional permissions or restrict the scope of access for a specific integration.
Environment Unified Models
You can specify one or more installed unified models using the environment_unified_model_id field. During the connection flow, Truto uses the OAuth scopes configured on those environment unified models for each integration. If you also specify scopes, those take precedence over the unified model scopes. This is useful when you want the connection to request permissions aligned with a specific unified API installation.
Static Gate
You can specify a static gate for an integrated account by providing the truto_static_gate_id field. When set, all outbound API requests made by this integrated account will be routed through the static gate's domain instead of directly to the Truto's API. This is useful for scenarios where you need to proxy requests through a specific domain or gateway. The static gate must be one you can see. For a link token that names an environment_id, it must also be in an environment of that environment's team, or it's a 404. Whatever the token, a connection only ever uses a gate of its own team, and another team's gate is ignored when its requests are made.
This field is the only way to set the gate for a connection. Because it selects the host that every credentialed request for the account is sent to, truto_static_gate_id is ignored if it arrives in the connecting browser's own request — in the context it posts to complete the connection, or in the query string of the OAuth connect URL — on either a new connection or a reconnect. Set it here, where it is checked against your environment, and it is carried through the whole flow.
Request Body
The context of the integrated account. You can find these in the Variables section of an integrated account in the Truto UI.
{"label":"Production Hubspot Account"}The environment to connect the new integrated account in. Ignored for API tokens, which use their own environment. Required for a dashboard session creating a link token for a new integrated account. Don't send it with integrated_account_id.
8a2b104d-74a6-47f2-b93e-c6b611e82391IDs of environment unified models (installed unified models) whose OAuth scopes should be used during the connection flow. When omitted, integration default scopes are used unless overridden by scopes. At most 50 IDs.
["2510eeff-2973-4803-9f51-caf1e95dbde8"]The ID of the integrated account you want to reauthorize. Do NOT specify tenant_id if you are reauthorizing an integrated account.
1ba1f401-7183-47c5-9e39-e8e257e3c795Session tokens only. The integration's name (for example hubspot) to connect. With a session token the body takes integration (connect) or integrated_account_id (reconnect) and ignores every other field.
hubspotIf set to true, the context of the integrated account will be persisted when reconnecting. Set to false by default.
falseThe URI where the user should be redirected after the connection flow is complete. This is especially useful when you are authenticating via a Desktop app.
https://example.com/redirectThe region where the new integrated account will be placed. Only applies when creating a new integrated account via the link token (ignored for reauthorization).
wnamwnamenamapaceu
OAuth scopes to request during authentication. These scopes will take precedence over unified model scopes and integration default scopes.
["read:users","write:contacts"]The ID of the tenant you want to create a link token for. Required if you are creating a link token for a new integrated account. Free-form up to 255 characters, excluding control characters, leading or trailing whitespace, and the dot segments . and ...
acme-1The ID of the static gate to associate with this integrated account. The static gate must be one you can see. For a link token that names an environment_id, it must also be in an environment of that environment's team, or it's a 404. Whatever the token, a connection only ever uses a gate of its own team, and another team's gate is ignored when its requests are made.
6c0e5a2d-8f3b-4c71-9d2e-4b5a7f1e3c90Response Body
The link token that can be used to initiate a connection flow. Valid for 7 days, and used up once a connection completes with it.
efe6413c-941a-4ca6-8f22-defbf758b824Errors
| Status | Description |
|---|---|
400 | Malformed body — or, on reauthorization, an integration nothing can connect. A body that sends When |
403 | The caller does not have access to the requested environment, or account creation is disabled. |
404 | The integrated_account_id is not one the caller can see. |
# Create a link token for a new connection
truto link-tokens create --tenant-id acme-1
# Or reconnect an existing account
truto link-tokens create --integrated-account-id '<integrated_account_id>'
# Full body with additional options
truto link-tokens create \
-b '{"tenant_id": "acme-1", "redirect_uri": "https://example.com/callback"}'import Truto from '@truto/truto-ts-sdk';
const truto = new Truto({
token: '<your_api_token>',
});
const result = await truto.linkToken.createForNewIntegration({
"tenant_id": "<tenant_id>"
});
console.log(result);import asyncio
from truto_python_sdk import TrutoApi
truto_api = TrutoApi(token="<your_api_token>")
async def main():
result = await truto_api.link_tokens.create({
"tenant_id": "<tenant_id>"
})
print(result)
asyncio.run(main())curl -X POST 'https://api.truto.one/link-token' \
-H 'Authorization: Bearer <your_api_token>' \
-H 'Content-Type: application/json' \
-d '{
"tenant_id": "acme-1"
}'const body = {
"tenant_id": "acme-1"
};
const response = await fetch('https://api.truto.one/link-token', {
method: 'POST',
headers: {
'Authorization': 'Bearer <your_api_token>',
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
const data = await response.json();
console.log(data);import requests
url = "https://api.truto.one/link-token"
headers = {
"Authorization": "Bearer <your_api_token>",
"Content-Type": "application/json",
}
params = {
}
payload = {
"tenant_id": "acme-1"
}
response = requests.post(url, headers=headers, params=params, json=payload)
print(response.json())