Skip to main content

Installation

To get started, you first need to install algoliasearch (or any other available API client package). You can find the full list of available packages here.

All of our clients comes with type definition, and are available for both browser and node environments.

bash
yarn add @experimental-api-clients-automation/algoliasearch
# or
npm install @experimental-api-clients-automation/algoliasearch
bash
yarn add @experimental-api-clients-automation/algoliasearch
# or
npm install @experimental-api-clients-automation/algoliasearch

Or use a specific package:

bash
yarn add @experimental-api-clients-automation/client-search
# or
npm install @experimental-api-clients-automation/client-search
bash
yarn add @experimental-api-clients-automation/client-search
# or
npm install @experimental-api-clients-automation/client-search

Without a package manager

Add the following JavaScript snippet to the <head> of your website:

html
<script src="https://cdn.jsdelivr.net/npm/@experimental-api-clients-automation/algoliasearch/dist/algoliasearch.umd.browser.js"></script>
html
<script src="https://cdn.jsdelivr.net/npm/@experimental-api-clients-automation/algoliasearch/dist/algoliasearch.umd.browser.js"></script>

Using the client

Then you need to import the correct package:

js
import { algoliasearch } from '@experimental-api-clients-automation/algoliasearch';
const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');
// And access analytics or personalization client
const analyticsClient = client.initAnalytics('<YOUR_APP_ID>', '<YOUR_API_KEY>');
const personalizationClient = client.initPersonalization(
'<YOUR_APP_ID>',
'<YOUR_API_KEY>',
'eu'
);
const searchRes = await client.search({
requests: [
{
indexName: '<YOUR_INDEX_NAME>',
query: '<YOUR_QUERY>',
},
],
});
const analyticsRes = await analyticsClient.getTopFilterForAttribute({
attribute: 'myAttribute1,myAttribute2',
index: '<YOUR_INDEX_NAME>',
});
console.log('[Results]', searchRes, analyticsRes);
js
import { algoliasearch } from '@experimental-api-clients-automation/algoliasearch';
const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');
// And access analytics or personalization client
const analyticsClient = client.initAnalytics('<YOUR_APP_ID>', '<YOUR_API_KEY>');
const personalizationClient = client.initPersonalization(
'<YOUR_APP_ID>',
'<YOUR_API_KEY>',
'eu'
);
const searchRes = await client.search({
requests: [
{
indexName: '<YOUR_INDEX_NAME>',
query: '<YOUR_QUERY>',
},
],
});
const analyticsRes = await analyticsClient.getTopFilterForAttribute({
attribute: 'myAttribute1,myAttribute2',
index: '<YOUR_INDEX_NAME>',
});
console.log('[Results]', searchRes, analyticsRes);
js
import { searchClient } from '@experimental-api-clients-automation/client-search';
const client = searchClient('<YOUR_APP_ID>', '<YOUR_API_KEY>');
js
import { searchClient } from '@experimental-api-clients-automation/client-search';
const client = searchClient('<YOUR_APP_ID>', '<YOUR_API_KEY>');

It is possible to customize the client by passing optional parameters:

js
const client = searchClient('<YOUR_APP_ID>', '<YOUR_API_KEY>', {
requester: customRequester(),
hosts: [
{
url: 'my.custom.host.net',
accept: 'read',
protocol: 'https',
},
],
});
js
const client = searchClient('<YOUR_APP_ID>', '<YOUR_API_KEY>', {
requester: customRequester(),
hosts: [
{
url: 'my.custom.host.net',
accept: 'read',
protocol: 'https',
},
],
});

Once the client is setup, you can play with the Algolia API!

js
const res = await client.search({
requests: [
{
indexName: '<YOUR_INDEX_NAME>',
query: '<YOUR_QUERY>',
},
],
});
console.log('[Results]', res);
js
const res = await client.search({
requests: [
{
indexName: '<YOUR_INDEX_NAME>',
query: '<YOUR_QUERY>',
},
],
});
console.log('[Results]', res);

Or with the personalization client

js
const res = await personalizationClient.getUserTokenProfile({
userToken: 'token',
});
console.log('[Results]', res);
js
const res = await personalizationClient.getUserTokenProfile({
userToken: 'token',
});
console.log('[Results]', res);