---
type: api
title: Update a cross-cluster API key
description: Update the attributes of an existing cross-cluster API key, which is used for API key based remote cluster access.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-security-update-cross-cluster-api-key
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-security-update-cross-cluster-api-key
products:
  - Elasticsearch
---

# Update a cross-cluster API key

Availability:

## Paths

- `PUT` `/_security/cross_cluster/api_key/{id}`

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

#### Path Parameters

- `id` (string Id)
  The ID of the cross-cluster API key to update.

## Description

Update the attributes of an existing cross-cluster API key, which is used for API key based remote cluster access.

To use this API, you must have at least the `manage_security` cluster privilege.
Users can only update API keys that they created.
To update another user's API key, use the `run_as` feature to submit a request on behalf of another user.

IMPORTANT: It's not possible to use an API key as the authentication credential for this API.
To update an API key, the owner user's credentials are required.

It's not possible to update expired API keys, or API keys that have been invalidated by the invalidate API key API.

This API supports updates to an API key's access scope, metadata, and expiration.
The owner user's information, such as the `username` and `realm`, is also updated automatically on every call.

NOTE: This API cannot update REST API keys, which should be updated by either the update API key or bulk update API keys API.

To learn more about how to use this API, refer to the [Update cross cluter API key API examples page](https://www.elastic.co/docs/reference/elasticsearch/rest-apis/update-cc-api-key-examples).

## Required authorization

* Cluster privileges: `manage_security`

[About adding remote clusters](https://www.elastic.co/docs/deploy-manage/remote-clusters/remote-clusters-api-key)

## Request Body

`application/json`

- `access` ({} Access) — required
  The access to be granted to this API key.
The access is composed of permissions for cross cluster search and cross cluster replication.
At least one of them must be specified.
When specified, the new access assignment fully replaces the previously assigned access.
  - `replication` ([] ReplicationAccess) — optional
    A list of indices permission entries for cross-cluster replication.
    - `names` (union IndexName | [] IndexName) — required
      A list of indices (or index name patterns) to which the permissions in this entry apply.
    - `allow_restricted_indices` (boolean · default: false) — optional
      This needs to be set to true if the patterns in the names field should cover system indices.
  - `search` ([] SearchAccess) — optional
    A list of indices permission entries for cross-cluster search.
    - `field_security` ({} FieldSecurity) — optional
      The document fields that the owners of the role have read access to.
      - `except` (string Fields) — optional
      - `grant` (string Fields) — optional
    - `names` (union IndexName | [] IndexName) — required
      A list of indices (or index name patterns) to which the permissions in this entry apply.
    - `query` (IndicesPrivilegesQuery) — optional
      A search query that defines the documents the owners of the role have access to. A document within the specified indices must match this query for it to be accessible by the owners of the role.
    - `allow_restricted_indices` (boolean · default: false) — optional
      Set to `true` if using wildcard or regular expressions for patterns that cover restricted indices. Implicitly, restricted indices have limited privileges that can cause pattern tests to fail. If restricted indices are explicitly included in the `names` list, Elasticsearch checks privileges against these indices regardless of the value set for `allow_restricted_indices`.
- `expiration` (string Duration) — optional
  The expiration time for the API key.
By default, API keys never expire. This property can be omitted to leave the value unchanged.
- `metadata` (Metadata) — optional
  Arbitrary metadata that you want to associate with the API key.
It supports nested data structure.
Within the metadata object, keys beginning with `_` are reserved for system usage.
When specified, this information fully replaces metadata previously associated with the API key.
- `certificate_identity` (string) — optional
  The certificate identity to associate with this API key.
This field is used to restrict the API key to connections authenticated by a specific TLS certificate.
The value should match the certificate's distinguished name (DN) pattern.
When specified, this fully replaces any previously assigned certificate identity.
To clear an existing certificate identity, explicitly set this field to `null`.
When omitted, the existing certificate identity remains unchanged.

## Response

`application/json`

- `updated` (boolean)
  If `true`, the API key was updated.
If `false`, the API key didn’t change because no change was detected.
## Code Examples

#### Console

```console
PUT /_security/cross_cluster/api_key/VuaCfGcBCdbkQm-e5aOx
{
  "access": {
    "replication": [
      {
        "names": ["archive"]
      }
    ]
  },
  "metadata": {
    "application": "replication"
  }
}
```

#### JavaScript

```javascript
const response = await client.security.updateCrossClusterApiKey({
  id: "VuaCfGcBCdbkQm-e5aOx",
  access: {
    replication: [
      {
        names: ["archive"],
      },
    ],
  },
  metadata: {
    application: "replication",
  },
});
```

#### Python

```python
resp = client.security.update_cross_cluster_api_key(
    id="VuaCfGcBCdbkQm-e5aOx",
    access={
        "replication": [
            {
                "names": [
                    "archive"
                ]
            }
        ]
    },
    metadata={
        "application": "replication"
    },
)
```

#### curl

```curl
curl -X PUT "$ELASTICSEARCH_URL/_security/cross_cluster/api_key/VuaCfGcBCdbkQm-e5aOx" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "access": {
      "replication": [
        {
          "names": [
            "archive"
          ]
        }
      ]
    },
    "metadata": {
      "application": "replication"
    }
  }'
```

#### Java

```java
client.security().updateCrossClusterApiKey(u -> u
    .access(a -> a
        .replication(r -> r
            .names("archive")
        )
    )
    .id("VuaCfGcBCdbkQm-e5aOx")
    .metadata("application", JsonData.fromJson("\"replication\""))
);
```

#### C#

```c#
var response = await client.Security
    .UpdateCrossClusterApiKeyAsync(id: "VuaCfGcBCdbkQm-e5aOx", d1 => d1
        .Access(d2 => d2
            .Replication(d3 => d3
                .Names(["archive"])
            )
        )
        .Metadata(new Dictionary<string, object>()
        {
            { "application", "replication" }
        })
    );
```

#### PHP

```php
$resp = $client->security()->updateCrossClusterApiKey([
    "id" => "VuaCfGcBCdbkQm-e5aOx",
    "body" => [
        "access" => [
            "replication" => array(
                [
                    "names" => array(
                        "archive",
                    ),
                ],
            ),
        ],
        "metadata" => [
            "application" => "replication",
        ],
    ],
]);
```

#### Ruby

```ruby
response = client.security.update_cross_cluster_api_key(
  id: "VuaCfGcBCdbkQm-e5aOx",
  body: {
    "access": {
      "replication": [
        {
          "names": [
            "archive"
          ]
        }
      ]
    },
    "metadata": {
      "application": "replication"
    }
  }
)
```

## Response Examples

#### Update cross cluster api key response example1

A successful response from `PUT /_security/cross_cluster/api_key/VuaCfGcBCdbkQm-e5aOx` that indicates that the API key was updated.

```json
{
  "updated": true
}
```

