Skip to main content

Getting started

Installation

To get started, you first need to install algoliasearch (or any other available API client package)

yarn add @experimental-api-clients-automation/algoliasearch

Or use a specific package to reduce bundle size:

yarn add @experimental-api-clients-automation/client-search

You can find the full list of available packages here.

Without a package manager

Add the JavaScript to your <head>

<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, depending on your choice:

import { algoliasearch } from '@experimental-api-clients-automation/algoliasearch';

const client = algoliasearch(appId, apiKey);

// And access analytics or personalization client
const analyticsClient = client.initAnalytics(analyticsAppId, analyticsApiKey);
const personalizationCilent = client.initPersonalization(
personalizationAppId,
personalizationApiKey,
'eu'
);
import { searchApi } from '@experimental-api-clients-automation/client-search';

const client = searchApi(appId, apiKey);

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

const client = searchApi(appId, apiKey, {
requester: customRequester(),
hosts: [
{
url: 'my.custom.host.net',
accept: 'read',
protocol: 'https',
},
],
});

Once the client is setup, you can enjoy all of Algolia API !

const res = await client.search({
indexName: 'my-index',
searchParams: { query: 'words to query' },
});

console.log('Search result', res.hits);

Or with the personalization client

const res = await personalizationCilent.getUserTokenProfile({
userToken: 'token',
});

console.log('User scores', res.scores);