The generated API clients are a work in progress, you can also find our stable clients on the Algolia documentation.

Skip to main content

Wait for an API key to be valid

The waitForApiKey method is only available in the search 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

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 });

update

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,
}});

delete

const response = await client.deleteApiKey({ key: 'myTestApiKey' });

// use typed response
console.log(response);

await client.waitForApiKey({ operation: "delete", key: response.key });