[[update-connector-api-key-id-api]]
=== Update connector API key ID API
++++
<titleabbrev>Update connector API key id</titleabbrev>
++++

preview::[]

Updates the `api_key_id` and/or `api_key_secret_id` field(s) of a connector, specifying:

. The ID of the API key used for authorization
. The ID of the Connector Secret where the API key is stored

The Connector Secret ID is only required for native connectors.
Connector clients do not use this field.
See the documentation for {enterprise-search-ref}/native-connectors.html#native-connectors-manage-API-keys-programmatically[managing native connector API keys programmatically^] for more details.

[[update-connector-api-key-id-api-request]]
==== {api-request-title}

`PUT _connector/<connector_id>/_api_key_id`

[[update-connector-api-key-id-api-prereq]]
==== {api-prereq-title}

* To sync data using connectors, it's essential to have the Elastic connectors service running.
* The `connector_id` parameter should reference an existing connector.
* The `api_key_id` parameter should reference an existing API key.
* The `api_key_secret_id` parameter should reference an existing Connector Secret containing an encoded API key value.

[[update-connector-api-key-id-api-path-params]]
==== {api-path-parms-title}

`<connector_id>`::
(Required, string)

[role="child_attributes"]
[[update-connector-api-key-id-api-request-body]]
==== {api-request-body-title}

`api_key_id`::
(Optional, string) ID of the API key that the connector will use to authorize access to required indices. Each connector can be associated with at most one API key.

`api_key_secret_id`::
(Optional, string) ID of the Connector Secret that contains the encoded API key. This should be the same API key as `api_key_id` references. This is only required for native connectors.

[[update-connector-api-key-id-api-response-codes]]
==== {api-response-codes-title}

`200`::
Connector `api_key_id` and/or `api_key_secret_id` field(s) successfully updated.

`400`::
The `connector_id` was not provided or the request payload was malformed.

`404` (Missing resources)::
No connector matching `connector_id` could be found.

[[update-connector-api-key-id-api-example]]
==== {api-examples-title}

The following example updates the `api_key_id` and `api_key_secret_id` field(s) for the connector with ID `my-connector`:

////
[source, console]
--------------------------------------------------
PUT _connector/my-connector
{
  "index_name": "search-google-drive",
  "name": "My Connector",
  "service_type": "google_drive"
}
--------------------------------------------------
// TESTSETUP

[source,console]
--------------------------------------------------
DELETE _connector/my-connector
--------------------------------------------------
// TEARDOWN
////

[source,console]
----
PUT _connector/my-connector/_api_key_id
{
    "api_key_id": "my-api-key-id",
    "api_key_secret_id": "my-connector-secret-id"
}
----

[source,console-result]
----
{
    "result": "updated"
}
----
