
# Delete a directory

`DELETE /v1/directories/{directory_id}` · permission `directories:write`

Deletes the directory at once and for good: its tokens (the identity provider's SCIM requests get `401` from then on), deprovision holds, groups, group memberships and directory user records are deleted in the same transaction. The deletion is audited as `directory.deleted`. Deleting an already deleted directory returns `404`.

## Request

| Field | Type | Required | Description |
|---|---|---|---|
| `directory_id` | path | yes | SCIM directory ID (`dir_…`). |

There is no request body.

## Response

`204 No Content`.

## Errors

| HTTP | code | When |
|---|---|---|
| 404 | `not_found` | The directory does not exist in this environment. |
| 401 | `unauthenticated` | The credential is missing, invalid or revoked. |
| 403 | `insufficient_permissions` | The credential lacks the required permission. |
| 429 | `rate_limited` | The rate limit was exceeded; retry after the `Retry-After` period. |
| 503 | `service_unavailable` | Directory sync is temporarily unavailable or not configured in this deployment; retry after the `Retry-After` period. |

## Example

```bash
curl -i -X DELETE "https://api.eu.keenauth.com/v1/directories/dir_01j9xm2n4p6q8r0s2t4v6w8y0z" \
  -H "Authorization: Bearer $KEENAUTH_SECRET_KEY"
```
