---
type: api
title: Delete user-managed service accounts
description: Delete a service account from a namespace of your own.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-security-delete-user-managed-service-account
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-security-delete-user-managed-service-account
products:
  - Elasticsearch
---

# Delete user-managed service accounts

Availability: Planned

## Paths

- `DELETE` `/_security/service/{namespace}/{service}`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#bearerauth)

#### Path Parameters

- `namespace` (string)
  The namespace, which is a top-level grouping of service accounts.
It must start with a letter or digit and can contain only letters, digits, hyphens, and underscores, up to a maximum of 128 characters.
It cannot be `elastic`, which is reserved for built-in service accounts.
- `service` (string)
  The service name.
It must start with a letter or digit and can contain only letters, digits, hyphens, and underscores, up to a maximum of 128 characters.

## Description

Delete a service account from a namespace of your own.

Deleting an account that still has service tokens is rejected unless `force` is `true`.
A forced delete leaves the tokens behind: they cannot authenticate while no account of that name exists, and recreating the account is rejected until they are deleted.

NOTE: The `elastic` namespace is reserved for the built-in service accounts that ship with Elasticsearch.
A name that no user-managed service account could have is rejected rather than reported as not found.
The `manage_service_account` privilege does not authorize this API.

## Required authorization

* Cluster privileges: `manage_security`

[More about service accounts](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/service-accounts)

## Query String Parameters

- `refresh` (enum Refresh · default: wait_for)
  If `wait_for` (the default) then wait for a refresh to make this operation visible to search, if `true` then refresh the affected shards to make this operation visible to search, if `false` then do nothing with refreshes.
  Values: `true`, `false`, `wait_for`
- `force` (boolean · default: false)
  If `false` (the default), deleting a service account that still has service tokens is rejected.
If `true`, the account is deleted and its tokens are left in place.

## Response

`application/json`

- `found` (boolean)
  If the service account is successfully deleted, the request returns `{"found": true}`.
Otherwise, the response will have status code 404 and `found` is set to `false`.
## Code Examples

#### Console

```console
DELETE /_security/service/my-namespace/my-service
```

#### JavaScript

```javascript
const response = await client.security.deleteUserManagedServiceAccount({
  namespace: "my-namespace",
  service: "my-service",
});
```

#### Python

```python
resp = client.security.delete_user_managed_service_account(
    namespace="my-namespace",
    service="my-service",
)
```

#### curl

```curl
curl -X DELETE "$ELASTICSEARCH_URL/_security/service/my-namespace/my-service" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### PHP

```php
$resp = $client->security()->deleteUserManagedServiceAccount([
    "namespace" => "my-namespace",
    "service" => "my-service",
]);
```

#### Ruby

```ruby
response = client.security.delete_user_managed_service_account(
  namespace: "my-namespace",
  service: "my-service"
)
```

## Response Examples

#### Delete user managed service account response example1

A successful response from `DELETE /_security/service/my-namespace/my-service`.

```json
{
  "found": true
}
```

