This is documentation for v3 of the PHP API clients, which is not the latest version. To see the documentation for the latest version, see PHP v4.

This is documentation for v2 of the Ruby API clients, which is not the latest version. To see the documentation for the latest version, see Ruby v3.

This is documentation for v4 of the JavaScript API clients, which is not the latest version. To see the documentation for the latest version, see JavaScript v5.

This is documentation for v3 of the Python API clients, which is not the latest version. To see the documentation for the latest version, see Python v4.

This is documentation for v8 of the Swift API clients, which is not the latest version. To see the documentation for the latest version, see Swift v9.

This is documentation for v2 of the Kotlin API clients, which is not the latest version. To see the documentation for the latest version, see Kotlin v3.

This is documentation for v6 of the C# API clients, which is not the latest version. To see the documentation for the latest version, see C# v7.

This is documentation for v3 of the Java API clients, which is not the latest version. To see the documentation for the latest version, see Java v4.

This is documentation for v3 of the Go API clients, which is not the latest version. To see the documentation for the latest version, see Go v4.

This is documentation for v1 of the Scala API clients, which is not the latest version. To see the documentation for the latest version, see Scala v2.

Required API Key: Admin

Method signature
$client->updateApiKey(string apiKey, [
  // All the following parameters are optional
  'acl'                     => array,
  'validity'                => integer,
  'maxQueriesPerIPPerHour'  => integer,
  'maxHitsPerQuery'         => integer,
  'indexes'                 => array,
  'referers'                => array,
  'queryParameters'         => string,
  'description'             => string,
])

You’re currently reading the JavaScript API client v4 documentation. Check the migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.

You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.

About this method

Replace every permission of an existing API key.

Any unspecified permission field will be reset to its default value. To ensure that existing permissions aren’t lost when applying an update, make sure to include the existing permissions you don’t want to change.

Examples

Read the Algolia CLI documentation for more information.

Update the permissions of an existing key

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Update an existing API key that is valid for 300 seconds
$res = $client->updateApiKey('YourAPIKey', [
  'acl' => ['search']
  'validity' => 300
]);

echo 'key=' . $res['key'] . "\n";

// Update an existing index-specific API key valid for 300 seconds,
// with a rate limit of 100 calls per hour per IP and a maximum of 20 hits
$res = $index->updateApiKey('YourAPIKey', [
  'acl' => ['search'],
  'validity' => 300,
  'maxQueriesPerIPPerHour' => 100,
  'maxHitsPerQuery' => 20
]);

echo 'key=' . $res['key'] . "\n";

Parameters

apiKey
type: string
default: no default
Required

API Key to update

acl
type: list
default: no default
Optional

Set of permissions associated with the key.

The possible access controls are:

  • Search (search): allowed to perform search operations.
  • Browse Index (browse): allowed to retrieve all index data with the browse endpoint.
  • Add records (addObject): allowed to add or update records in the index.
  • Delete records (deleteObject): allowed to delete an existing record.
  • List indices (listIndexes): allowed to get a list of all existing indices.
  • Delete index (deleteIndex): allowed to delete an index.
  • Get index settings (settings): allowed to read all index settings.
  • Set index settings (editSettings): allowed to update all index settings.
  • Use analytics API (analytics): allowed to retrieve data with the Analytics API.
  • Use recommendation API (recommendation): allowed to interact with the Recommendation API.
  • Use usage API (usage): allowed to retrieve data with the Usage API.
  • Access logs (logs): allowed to query the logs.
  • Get unretrievable attributes (seeUnretrievableAttributes): allowed to retrieve unretrievableAttributes for all operations that return records.
validity
type: list
default: no expiration date
Optional

A Unix timestamp used to define the expiration date of the API key.

This must be a positive integer.

maxHitsPerQuery
type: list
default: 0 (unlimited)
Optional

Specify the maximum number of hits this API key can retrieve in one call. This parameter can be used to protect you from attempts at retrieving your entire index contents by massively querying the index.

This must be a positive integer.

maxQueriesPerIPPerHour
type: list
default: 0 (no rate limit)
Optional

Specify the maximum number of API calls allowed from an IP address per hour. Each time an API call is performed with this key, a check is performed. If the IP at the source of the call did more than this number of calls in the last hour, a 429 code is returned.

This must be a positive integer.

This parameter can be used to protect you from attempts at retrieving your entire index contents by massively querying the index.

indexes
type: list
default: [] (all indices)
Optional

Specify the list of targeted indices. You can target all indices starting with a prefix or ending with a suffix using the ‘*’ character. For example, “dev_*” matches all indices starting with “dev_” and “*_dev” matches all indices ending with “_dev”.

referers
type: list
default: [] (all referers)
Optional

Specify the list of referers. You can target all referers starting with a prefix, ending with a suffix using the ‘*’ character. For example, “https://algolia.com/*” matches all referers starting with “https://algolia.com/” and “*.algolia.com” matches all referers ending with “.algolia.com”. If you want to allow the domain algolia.com you can use “*algolia.com/*”.

queryParameters
type: key/value mapping
default: "" (no query parameters)
Optional

Specify the list of query parameters. You can force the query parameters for a query using the url string format. Example: “typoTolerance=strict&ignorePlurals=false”

description
type: string
default: ""
Optional

Specify a description to describe where the key is used.

Response

This section shows the JSON response returned by the API. Each API client encapsulates this response inside objects specific to the programming language, so that the actual response might be different. You can view the response by using the getLogs method. Don’t rely on the order of attributes in the response, as JSON doesn’t guarantee the ordering of keys in objects.

JSON format

1
2
3
4
{
  "key": "1eb37de6308abdccf9b760ddacb418b4",
  "updatedAt": "2017-12-16T22:21:31.871Z"
}
Field Description
key
string

The updated key.

updatedAt
string

The date at which the key was updated.

Did you find this page helpful?