# Create link token

> Source: https://truto.one/docs/api-reference/admin/link-token/create/

`POST /link-token`

Resource: **Link token**

## Request body

- **`tenant_id`** _(string)_
  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.
- **`integrated_account_id`** _(string)_
  The ID of the integrated account you want to reauthorize. Do NOT specify `tenant_id` if you are reauthorizing an integrated account.
- **`context`** _(object)_
  The context of the integrated account. You can find these in the `Variables` section of an integrated account in the Truto UI.
- **`redirect_uri`** _(string)_
  The 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.
- **`scopes`** _(array<string>)_
  OAuth scopes to request during authentication. These scopes will take precedence over unified model scopes and integration default scopes.
- **`persist_previous_context`** _(boolean)_
  If set to true, the context of the integrated account will be persisted when reconnecting. Set to false by default.
- **`truto_static_gate_id`** _(string)_
  The ID of the static gate to associate with this integrated account. The static gate must be accessible to the user's environment.
- **`region`** _(string)_
  The region where the new integrated account will be placed. Only applies when creating a new integrated account via the link token (ignored for reauthorization).
  Allowed: `wnam`, `enam`, `apac`, `eu`

## Response body

- **`link_token`** _(string)_
  The link token that can be used to initiate a connection flow.

## Code examples

### curl

```bash
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",
  "integrated_account_id": "1ba1f401-7183-47c5-9e39-e8e257e3c795",
  "context": "{\n  \"label\": \"Production Hubspot Account\"\n}\n",
  "redirect_uri": "https://example.com/redirect",
  "scopes": [
    "read:users",
    "write:contacts"
  ],
  "persist_previous_context": false,
  "truto_static_gate_id": "1ba1f401-7183-47c5-9e39-e8e257e3c795",
  "region": "wnam"
}'
```

### JavaScript

```javascript
const body = {
  "tenant_id": "acme-1",
  "integrated_account_id": "1ba1f401-7183-47c5-9e39-e8e257e3c795",
  "context": "{\n  \"label\": \"Production Hubspot Account\"\n}\n",
  "redirect_uri": "https://example.com/redirect",
  "scopes": [
    "read:users",
    "write:contacts"
  ],
  "persist_previous_context": false,
  "truto_static_gate_id": "1ba1f401-7183-47c5-9e39-e8e257e3c795",
  "region": "wnam"
};

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);
```

### Python

```python
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",
    "integrated_account_id": "1ba1f401-7183-47c5-9e39-e8e257e3c795",
    "context": "{\n  \"label\": \"Production Hubspot Account\"\n}\n",
    "redirect_uri": "https://example.com/redirect",
    "scopes": [
        "read:users",
        "write:contacts"
    ],
    "persist_previous_context": False,
    "truto_static_gate_id": "1ba1f401-7183-47c5-9e39-e8e257e3c795",
    "region": "wnam"
}

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

### Truto TS SDK

```typescript
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);
```

### Truto Python SDK

```python
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())
```
