Getting Started
- JavaScript
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.
yarn add @experimental-api-clients-automation/algoliasearch
Or use a specific package:
yarn add @experimental-api-clients-automation/client-search
Without a package manager
Add the following JavaScript snippet to the <head>
of your website:
<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:
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 personalizationCilent = client.initPersonalization(
'<YOUR_APP_ID>',
'<YOUR_API_KEY>',
'eu'
);
const searchRes = await client.search({
indexName: '<YOUR_INDEX>',
searchParams: { query: searchQuery },
});
const analyticsRes = await analyticsClient.getTopFilterForAttribute({
attribute: 'myAttribute1,myAttribute2',
index: '<YOUR_INDEX>',
});
console.log('[Results]', searchRes, analyticsRes);
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:
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!
const res = await client.search({
indexName: '<YOUR_INDEX>',
searchParams: { query: 'words to query' },
});
console.log('[Results]', res);
Or with the personalization
client
const res = await personalizationClient.getUserTokenProfile({
userToken: 'token',
});
console.log('[Results]', res);