# Deleting tenants

> Source: https://truto.one/docs/guides/tenants/deleting-tenants/

Deleting a tenant is permanent — the row is gone and can't be restored. Truto enforces one important guard: **a tenant with any connected integrated accounts can't be deleted.** Delete (or bulk-delete) its accounts first, then delete the tenant.

## The delete guard

`DELETE /tenant/:id` returns `409 Conflict` with the message *"Can't delete tenant with connected accounts."* if any integrated account still references this tenant in this environment. This is a hard rule enforced by the API — the same guard runs whether you're calling from the dashboard, API, or CLI.

The reason: integrated accounts and their credentials are the primary reason the tenant exists. Removing the tenant would orphan them (or, worse, silently break downstream sync jobs and webhooks that expect the tenant reference). Truto makes you deal with the accounts explicitly.

## From the dashboard

1. Open [Tenants](https://app.truto.one/tenants).
2. Click into the tenant you want to delete. The detail page lists every integrated account owned by this tenant.
3. If the tenant has connected accounts:
   - Select accounts individually with the checkbox column, or click the header checkbox to select all.
   - Click **Delete N selected accounts**, confirm in the modal.
4. Once no accounts remain, click the **⋮** menu on the tenant row (in the list) and choose **Delete**. Confirm in the modal.

The tenant is gone from the list. This is an irreversible operation.

## From the API

Delete a tenant that has no accounts:

```bash
curl --location --request DELETE 'https://api.truto.one/tenant/acme-corp' \
--header 'Authorization: Bearer <your-api-token>'
```

Response (`200 OK`):

```json
{ "id": "acme-corp", "environment_id": "…", "name": "Acme Corp", "metadata": {…}, "created_at": "…", "updated_at": "…" }
```

If the tenant still has accounts (`409 Conflict`):

```json
{ "statusCode": 409, "error": "Conflict", "message": "Can't delete tenant with connected accounts." }
```

## Bulk-deleting accounts first

If the tenant has many accounts, delete them with `POST /integrated-account/bulk-delete` (capped at 1000 accounts per request — repeat until `matched_count < 1000`):

```bash
curl --location 'https://api.truto.one/integrated-account/bulk-delete' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-api-token>' \
--data '{
    "tenant_id": "acme-corp"
}'
```

Response:

```json
{ "matched_count": 3, "deleted_count": 3 }
```

Or delete a subset by account UUIDs (max 99 per request due to D1's parameter limit):

```json
{ "ids": ["79a39d69-e27e-49cb-b9a9-79f5eea7aa26", "0c74a4ad-7b8e-4f3a-9c1d-2e4f5a6b7c8d"] }
```

Exactly one of `tenant_id` or `ids` must be supplied. The `tenant_id` branch is capped at **1000 accounts per request**; if the tenant has more, repeat the call until `matched_count` is less than 1000. Once all accounts are gone, `DELETE /tenant/:id` succeeds.

## From the CLI

```bash
# List the accounts first
truto accounts list --tenant-id acme-corp

# Delete them via bulk-delete (curl; no CLI subcommand yet), then delete the tenant
# curl -X POST https://api.truto.one/integrated-account/bulk-delete \
#   -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' \
#   -d '{"tenant_id":"acme-corp"}'
truto tenants delete acme-corp
```

See [Admin resources — Tenants](/docs/cli/admin-resources#tenants).

## Recovery

There is no undelete. If you delete a tenant and need it back, re-create it with the same `id`; you'll get a fresh row (new `created_at`, no metadata). Integrated accounts that referenced it are already gone — they don't come back with the tenant.
