# Multi Tenant Instance Updated API

> Drop the connection pools of a tenant on every API Maker server after its connection string changed, with the multi tenant instance updated system API, so its next request uses the new database.

Source: https://docs.apimaker.dev/v1/docs/apis-all/system-apis/system-generated-multi-tenant-instance-updated-api.html

Call it when the connection string of a tenant of a [multi-tenant](https://docs.apimaker.dev/v1/docs/features/multi-tenant.html) instance changes in the tenants table : every server drops the connection pools of that tenant and the cached answers of the instance and of the tenants table, so the next request of the tenant reads its row again and connects to the new database.

| | |
|---|---|
| Method | POST |
| URL | `/api/system-api/admin/multi-tenant-instance-updated` : `admin` is the user path of your account |
| Body | `{ instanceName, username }` or an array of them |
| Answer | `data` : one answer per item, `{ success, data }` |
| From code | [`g.sys.system.multiTenantInstanceUpdated`](https://docs.apimaker.dev/v1/examples/sys/system/multiTenantInstanceUpdated.html) |

## The call

**Body : one tenant of one instance**

```json
{ "instanceName": "crm", "username": "acme" }
```

**Body : several**

```json
[ { "instanceName": "crm", "username": "acme" }, { "instanceName": "billing", "username": "acme" } ]
```

**Answer**

```json
{
    "success": true,
    "statusCode": 200,
    "data": [
        { "success": true, "data": true },
        { "success": false, "data": false, "error": { "code": 400, "message": "Instance 'billing' is not a multi tenant structure instance." } }
    ]
}
```

- Each item is answered on its own : an unknown instance (404) or an instance which is not multi-tenant (400) does not stop the other items.
- Both fields are required.
- Until this API is called, the servers keep using the pools they have. For PostgreSQL, the pools of every database of the tenant are dropped.

## From code

```typescript
await g.sys.system.multiTenantInstanceUpdated({ instanceName: 'crm', username: 'acme' });
```

## Access and settings

- Over HTTP, a system API answers once its [settings](https://docs.apimaker.dev/v1/docs/settings/systemApiSettings.html) give it `apiAccessType: TOKEN_ACCESS` (the token of an API user whose [group](https://docs.apimaker.dev/v1/docs/apis-security/api-group-permission.html) grants this system API, in `x-am-authorization`) or `IS_PUBLIC`. Without settings it is `NO_ACCESS` : your code calls it through `g.sys`, the admin panel tests it, and an HTTP call is refused.
- The settings can also cache the answer or require person tokens (`authProviders`) ; [pre and post hooks](https://docs.apimaker.dev/v1/docs/apis-all/hooks/preHook-api.html) run around it like around any API.
- The [request headers](https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html) apply : `x-am-response-case`, `x-am-content-type-response`, `x-am-internationalization`, `x-am-tenant-username`…

## Errors

| Code | When |
|---|---|
| `400` | The body is wrong : the message names the missing or invalid key. |
| `401` | No valid API user token, or the API is `NO_ACCESS` : `You are not authorized to access this API.` |
| `403` | No group grants this system API. |

## Related

- [All APIs at a glance](https://docs.apimaker.dev/v1/docs/apis-all/overview.html) · [Response format](https://docs.apimaker.dev/v1/docs/apis-all/response-format.html) · [System API settings](https://docs.apimaker.dev/v1/docs/settings/systemApiSettings.html) · [System APIs from code](https://docs.apimaker.dev/v1/examples/sys/system/system.html)
