# Refresh the mapping cache

> Source: https://truto.one/docs/api-reference/admin/integrated-accounts/refresh-mapping-cache/

`POST /integrated-account/refresh-mapping-cache`

Resource: **Integrated accounts**

Truto caches the resolved unified models, unified mappings and integration configurations that every unified and proxy API request reads, so those requests do not have to fetch them again on each call. That cache expires on a timer, so an edit becomes visible on its own within roughly 23 minutes without calling anything.
Call this endpoint right after editing a unified model, a unified mapping, or an integration's resources / API paths to cut that wait short.
**This is best-effort.** It clears Truto's shared cache and the per-connection caches in the environment. It cannot purge the per-region edge cache, so a region already holding a copy can keep serving the previous value for up to roughly 6 minutes. A request that was already reading the previous value when the refresh ran can also put it back into the shared cache as it finishes. That, and the per-connection clears continuing in the background, is why the response is `202 Accepted` rather than `200 OK`.
Pass `integration_id` when the edit was to that integration — its configuration, its API paths, or one of its mappings. Only that integration's connections can hold the affected entries, so naming it keeps the work proportional. Omit it after editing a unified model itself, which every connection in the environment caches.
`integration_id` is also **required** to clear that integration's cached configuration. That entry is not scoped to an environment, so a call without `integration_id` cannot identify it and leaves it cached until it expires on its own. Unified models and unified mappings are cleared either way.

## Request body

- **`environment_id`** _(string)_
  The environment whose cache to refresh. Optional when authenticating with an API token, which is already scoped to one environment — required otherwise.
- **`integration_id`** _(string)_
  Restrict the per-connection clears to this integration's connections, and also drop its cached integration configuration. Must be an integration installed in this environment.

## Response body

- **`environment_id`** _(string)_
  The environment the refresh was applied to.
- **`integration_id`** _(string)_
  The integration the refresh was narrowed to, if any.
- **`deleted_cache_key_count`** _(integer)_
  How many shared cache entries were deleted.
- **`cache_keys_truncated`** _(boolean)_
  True when the sweep did not finish — some shared entries are still cached and will expire on their own. Call again to continue.
- **`integrated_account_count`** _(integer)_
  How many of the environment's connections are having their per-connection cache cleared.
- **`integrated_accounts_truncated`** _(boolean)_
  True when the environment has more connections than one refresh covers, so some keep their cached copy until it expires.
- **`message`** _(string)_
  The same caveat in prose, safe to surface to a user.

## Errors

| Status | Description |
| :----- | :---------- |
| `400` | environment_id is required and could not be inferred from the credential. |
| `403` | Forbidden — you do not have access to this environment. |
| `404` | The integration named by integration_id is not installed in this environment. |

## Code examples

### curl

```bash
curl -X POST 'https://api.truto.one/integrated-account/refresh-mapping-cache' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "environment_id": "9f1d8f52-6b4c-4c4e-9a0e-1b2c3d4e5f60",
  "integration_id": "1ba1f401-7183-47c5-9e39-e8e257e3c795"
}'
```

### JavaScript

```javascript
const body = {
  "environment_id": "9f1d8f52-6b4c-4c4e-9a0e-1b2c3d4e5f60",
  "integration_id": "1ba1f401-7183-47c5-9e39-e8e257e3c795"
};

const response = await fetch('https://api.truto.one/integrated-account/refresh-mapping-cache', {
  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/refresh-mapping-cache"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "environment_id": "9f1d8f52-6b4c-4c4e-9a0e-1b2c3d4e5f60",
    "integration_id": "1ba1f401-7183-47c5-9e39-e8e257e3c795"
}

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