Wait for an API key to be valid
The
waitForApiKey
method is only available in thesearch
client context.
Adding, updating or deleting API keys is not always instantaneous, which is why you might want to ensure the job has been processed before jumping to an other task.
We provide a waitForApiKey
helper method for you to easily wait for a specific operation
made on a key
.
add
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
using Algolia.Search.Clients;
using Algolia.Search.Http;
var client = new SearchClient(new SearchConfig("YOUR_APP_ID", "YOUR_API_KEY"));
var response = await client.AddApiKeyAsync(
new ApiKey
{
Acl = new List<Acl> { Enum.Parse<Acl>("Search"), Enum.Parse<Acl>("AddObject") },
Description = "my new api key",
Validity = 300,
MaxQueriesPerIPPerHour = 100,
MaxHitsPerQuery = 20,
}
);
await client.WaitForApiKeyAsync(ApiKeyOperation.Add, response.Key);
import 'package:algolia_client_search/algolia_client_search.dart';
final client = SearchClient(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
final response = await client.addApiKey(
apiKey: ApiKey(
acl: [
Acl.fromJson("search"),
Acl.fromJson("addObject"),
],
description: "my new api key",
validity: 300,
maxQueriesPerIPPerHour: 100,
maxHitsPerQuery: 20,
),
);
waitForApiKey.add is not implemented in dart
import "github.com/algolia/algoliasearch-client-go/v4/algolia/search"
client, err := search.NewClient("YOUR_APP_ID", "YOUR_API_KEY")
response, err := client.AddApiKey(client.NewApiAddApiKeyRequest(
search.NewEmptyApiKey().SetAcl(
[]search.Acl{search.Acl("search"), search.Acl("addObject")}).SetDescription("my new api key").SetValidity(300).SetMaxQueriesPerIPPerHour(100).SetMaxHitsPerQuery(20),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
waitResponse, err := client.WaitForApiKey(search.API_KEY_OPERATION_ADD, response.Key, nil)
if err != nil {
panic(err)
}
import com.algolia.api.SearchClient;
import com.algolia.model.search.*;
SearchClient client = new SearchClient("YOUR_APP_ID", "YOUR_API_KEY");
client.addApiKey(
new ApiKey()
.setAcl(List.of(Acl.SEARCH, Acl.ADD_OBJECT))
.setDescription("my new api key")
.setValidity(300)
.setMaxQueriesPerIPPerHour(100)
.setMaxHitsPerQuery(20)
);
client.waitForApiKey(ApiKeyOperation.ADD, response.Key, null)
import { searchClient } from '@algolia/client-search';
const client = searchClient('YOUR_APP_ID', 'YOUR_API_KEY');
const response = await client.addApiKey({
acl: ['search', 'addObject'],
description: 'my new api key',
validity: 300,
maxQueriesPerIPPerHour: 100,
maxHitsPerQuery: 20,
});
// use typed response
console.log(response);
await client.waitForApiKey({ operation: "add", key: response.key });
import com.algolia.client.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
var response = client.addApiKey(
apiKey = ApiKey(
acl = listOf(Acl.entries.first { it.value == "search" }, Acl.entries.first { it.value == "addObject" }),
description = "my new api key",
validity = 300,
maxQueriesPerIPPerHour = 100,
maxHitsPerQuery = 20,
),
)
// Use the response
println(response)
waitForApiKey.add is not implemented in kotlin
use Algolia\AlgoliaSearch\Api\SearchClient;
$client = SearchClient::create('<YOUR_APP_ID>', '<YOUR_API_KEY>');
$response = $client->addApiKey(
['acl' => [
'search',
'addObject',
],
'description' => 'my new api key',
'validity' => 300,
'maxQueriesPerIPPerHour' => 100,
'maxHitsPerQuery' => 20,
],
);
// play with the response
var_dump($response);
$client->waitForApiKey('add', $response['key']);
from algoliasearch.search.client import SearchClient
_client = SearchClient("YOUR_APP_ID", "YOUR_API_KEY")
response = await _client.add_api_key(
api_key={
"acl": [
"search",
"addObject",
],
"description": "my new api key",
"validity": 300,
"maxQueriesPerIPPerHour": 100,
"maxHitsPerQuery": 20,
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_api_key(operation="add", key=response.key)
require 'algolia'
client = Algolia::SearchClient.create('YOUR_APP_ID', 'YOUR_API_KEY')
response = client.add_api_key(
ApiKey.new(
acl: ['search', 'addObject'],
description: "my new api key",
validity: 300,
max_queries_per_ip_per_hour: 100,
max_hits_per_query: 20
)
)
# use the class directly
puts response
# print the JSON response
puts response.to_json
await client.wait_for_api_key(operation="add", key=response.key)
import algoliasearch.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
val response = client.addApiKey(
apiKey = ApiKey(
acl = Seq(Acl.withName("search"), Acl.withName("addObject")),
description = Some("my new api key"),
validity = Some(300),
maxQueriesPerIPPerHour = Some(100),
maxHitsPerQuery = Some(20)
)
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
waitForApiKey.add is not implemented in scala
import Search
let client = try SearchClient(appID: "YOUR_APP_ID", apiKey: "YOUR_API_KEY")
let response = try await client.addApiKey(apiKey: ApiKey(
acl: [Acl.search, Acl.addObject],
description: "my new api key",
maxHitsPerQuery: 20,
maxQueriesPerIPPerHour: 100,
validity: 300
))
try await client.waitForApiKey(with: response.key, operation: ApiKeyOperation.add)
update
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
var response = await client.UpdateApiKeyAsync(
"myApiKey",
new ApiKey
{
Acl = new List<Acl> { Enum.Parse<Acl>("Search"), Enum.Parse<Acl>("AddObject") },
Validity = 300,
MaxQueriesPerIPPerHour = 100,
MaxHitsPerQuery = 20,
}
);
await client.WaitForApiKeyAsync(ApiKeyOperation.Update, response.Key, {
Acl = new List<Acl> { Enum.Parse<Acl>("Search"), Enum.Parse<Acl>("AddObject") },
Validity = 300,
MaxQueriesPerIPPerHour = 100,
MaxHitsPerQuery = 20,
});
final response = await client.updateApiKey(
key: "myApiKey",
apiKey: ApiKey(
acl: [
Acl.fromJson("search"),
Acl.fromJson("addObject"),
],
validity: 300,
maxQueriesPerIPPerHour: 100,
maxHitsPerQuery: 20,
),
);
waitForApiKey.update is not implemented in dart
response, err := client.UpdateApiKey(client.NewApiUpdateApiKeyRequest(
"myApiKey",
search.NewEmptyApiKey().SetAcl(
[]search.Acl{search.Acl("search"), search.Acl("addObject")}).SetValidity(300).SetMaxQueriesPerIPPerHour(100).SetMaxHitsPerQuery(20),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
waitResponse, err := client.WaitForApiKey(search.API_KEY_OPERATION_UPDATE, response.Key, search.NewEmptyApiKey().SetAcl([]search.Acl{search.Acl("search"), search.Acl("addObject")}).SetValidity(300).SetMaxQueriesPerIPPerHour(100).SetMaxHitsPerQuery(20))
if err != nil {
panic(err)
}
client.updateApiKey(
"myApiKey",
new ApiKey().setAcl(List.of(Acl.SEARCH, Acl.ADD_OBJECT)).setValidity(300).setMaxQueriesPerIPPerHour(100).setMaxHitsPerQuery(20)
);
client.waitForApiKey(ApiKeyOperation.UPDATE, response.Key, new ApiKey()
.setAcl(List.of(Acl.SEARCH, Acl.ADD_OBJECT))
.setValidity(300)
.setMaxQueriesPerIPPerHour(100)
.setMaxHitsPerQuery(20))
const response = await client.updateApiKey({
key: 'myApiKey',
apiKey: {
acl: ['search', 'addObject'],
validity: 300,
maxQueriesPerIPPerHour: 100,
maxHitsPerQuery: 20,
},
});
// use typed response
console.log(response);
await client.waitForApiKey({ operation: "update", key: response.key, apiKey: {
acl: ['search', 'addObject'],
validity: 300,
maxQueriesPerIPPerHour: 100,
maxHitsPerQuery: 20,
}});
var response = client.updateApiKey(
key = "myApiKey",
apiKey = ApiKey(
acl = listOf(Acl.entries.first { it.value == "search" }, Acl.entries.first { it.value == "addObject" }),
validity = 300,
maxQueriesPerIPPerHour = 100,
maxHitsPerQuery = 20,
),
)
// Use the response
println(response)
waitForApiKey.update is not implemented in kotlin
$response = $client->updateApiKey(
'myApiKey',
['acl' => [
'search',
'addObject',
],
'validity' => 300,
'maxQueriesPerIPPerHour' => 100,
'maxHitsPerQuery' => 20,
],
);
// play with the response
var_dump($response);
$client->waitForApiKey('update', $response['key'], [
'acl' => [
'search',
'addObject',
],
'validity' => 300,
'maxQueriesPerIPPerHour' => 100,
'maxHitsPerQuery' => 20,
]);
response = await _client.update_api_key(
key="myApiKey",
api_key={
"acl": [
"search",
"addObject",
],
"validity": 300,
"maxQueriesPerIPPerHour": 100,
"maxHitsPerQuery": 20,
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_api_key(operation="update", key=response.key, api_key={
"acl": [
"search",
"addObject",
],
"validity": 300,
"maxQueriesPerIPPerHour": 100,
"maxHitsPerQuery": 20,
})
response = client.update_api_key(
"myApiKey",
ApiKey.new(
acl: ['search', 'addObject'],
validity: 300,
max_queries_per_ip_per_hour: 100,
max_hits_per_query: 20
)
)
# use the class directly
puts response
# print the JSON response
puts response.to_json
await client.wait_for_api_key(operation="update", key=response.key, api_key=ApiKey.new(
acl: ['search', 'addObject'],
validity: 300,
max_queries_per_ip_per_hour: 100,
max_hits_per_query: 20
))
val response = client.updateApiKey(
key = "myApiKey",
apiKey = ApiKey(
acl = Seq(Acl.withName("search"), Acl.withName("addObject")),
validity = Some(300),
maxQueriesPerIPPerHour = Some(100),
maxHitsPerQuery = Some(20)
)
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
waitForApiKey.update is not implemented in scala
let response = try await client.updateApiKey(
key: "myApiKey",
apiKey: ApiKey(
acl: [Acl.search, Acl.addObject],
maxHitsPerQuery: 20,
maxQueriesPerIPPerHour: 100,
validity: 300
)
)
try await client.waitForApiKey(with: response.key, operation: ApiKeyOperation.update, apiKey: ApiKey(
acl: [Acl.search, Acl.addObject],
maxHitsPerQuery: 20,
maxQueriesPerIPPerHour: 100,
validity: 300
))
delete
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
var response = await client.DeleteApiKeyAsync("myTestApiKey");
await client.WaitForApiKeyAsync(ApiKeyOperation.Delete, response.Key);
final response = await client.deleteApiKey(
key: "myTestApiKey",
);
waitForApiKey.delete is not implemented in dart
response, err := client.DeleteApiKey(client.NewApiDeleteApiKeyRequest(
"myTestApiKey",
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
waitResponse, err := client.WaitForApiKey(search.API_KEY_OPERATION_DELETE, response.Key, nil)
if err != nil {
panic(err)
}
client.deleteApiKey("myTestApiKey");
client.waitForApiKey(ApiKeyOperation.DELETE, response.Key, null)
const response = await client.deleteApiKey({ key: 'myTestApiKey' });
// use typed response
console.log(response);
await client.waitForApiKey({ operation: "delete", key: response.key });
var response = client.deleteApiKey(
key = "myTestApiKey",
)
// Use the response
println(response)
waitForApiKey.delete is not implemented in kotlin
$response = $client->deleteApiKey(
'myTestApiKey',
);
// play with the response
var_dump($response);
$client->waitForApiKey('delete', $response['key']);
response = await _client.delete_api_key(
key="myTestApiKey",
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_api_key(operation="delete", key=response.key)
response = client.delete_api_key("myTestApiKey")
# use the class directly
puts response
# print the JSON response
puts response.to_json
await client.wait_for_api_key(operation="delete", key=response.key)
val response = client.deleteApiKey(
key = "myTestApiKey"
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
waitForApiKey.delete is not implemented in scala
let response = try await client.deleteApiKey(key: "myTestApiKey")
try await client.waitForApiKey(with: response.key, operation: ApiKeyOperation.delete)