---
type: api
title: Clear service account token caches
description: Evict a subset of all entries from the service account token caches.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-security-clear-cached-service-tokens
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-security-clear-cached-service-tokens
products:
  - Elasticsearch
---

# Clear service account token caches

Availability:

## Paths

- `POST` `/_security/service/{namespace}/{service}/credential/token/{name}/_clear_cache`

- [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.
- `service` (string)
  The name of the service, which must be unique within its namespace.
- `name` (union Name | [] Name)
  A comma-separated list of token names to evict from the service account token caches.
Use a wildcard (`*`) to evict all tokens that belong to a service account.
It does not support other wildcard patterns.

## Description

Evict a subset of all entries from the service account token caches.
Two separate caches exist for service account tokens: one cache for tokens backed by the `service_tokens` file, and another for tokens backed by the `.security` index.
This API clears matching entries from both caches.

The cache for service account tokens backed by the `.security` index is cleared automatically on state changes of the security index.
The cache for tokens backed by the `service_tokens` file is cleared automatically on file changes.

## 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)

## Response

`application/json`

- `_nodes` ({} NodeStatistics)
  - `failures` ([] ErrorCause)
    - `type` (string)
      The type of error
    - `reason` (union string) — nullable
      A human-readable explanation of the error, in English.
      One of: `string`
    - `stack_trace` (string)
      The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
    - `caused_by` ({} ErrorCause) — recursive
      Same fields as `failures` in `_nodes`
    - `root_cause` ([] ErrorCause) — recursive
      Same fields as `failures` in `_nodes`
    - `suppressed` ([] ErrorCause) — recursive
      Same fields as `failures` in `_nodes`
  - `total` (number)
    Total number of nodes selected by the request.
  - `successful` (number)
    Number of nodes that responded successfully to the request.
  - `failed` (number)
    Number of nodes that rejected the request or failed to respond. If this value is not 0, a reason for the rejection or failure is included in the response.
- `cluster_name` (string Name)
- `nodes` (map string to ClusterNode)
  Map values ({} ClusterNode)
  - `name` (string Name)
## Code Examples

#### Console

```console
POST /_security/service/elastic/fleet-server/credential/token/token1/_clear_cache
```

#### JavaScript

```javascript
const response = await client.security.clearCachedServiceTokens({
  namespace: "elastic",
  service: "fleet-server",
  name: "token1",
});
```

#### Python

```python
resp = client.security.clear_cached_service_tokens(
    namespace="elastic",
    service="fleet-server",
    name="token1",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_security/service/elastic/fleet-server/credential/token/token1/_clear_cache" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.security().clearCachedServiceTokens(c -> c
    .name("token1")
    .namespace("elastic")
    .service("fleet-server")
);
```

#### C#

```c#
var response = await client.Security.ClearCachedServiceTokensAsync(@namespace: "elastic", service: "fleet-server", name: new[] { "token1" });
```

#### PHP

```php
$resp = $client->security()->clearCachedServiceTokens([
    "namespace" => "elastic",
    "service" => "fleet-server",
    "name" => "token1",
]);
```

#### Ruby

```ruby
response = client.security.clear_cached_service_tokens(
  namespace: "elastic",
  service: "fleet-server",
  name: "token1"
)
```

