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

Skip to main content

Installation

warning

The amount of changes in this new version is significant. If you are upgrading for v4, you should thoroughly test your application before deploying to production.

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

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

yarn add algoliasearch@alpha
# or
npm install algoliasearch@alpha

Or use a specific package:

yarn add @algolia/client-search@alpha
# or
npm install @algolia/client-search@alpha

Without a package manager

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

<script src="https://cdn.jsdelivr.net/npm/algoliasearch/dist/algoliasearch.umd.js"></script>

Using the client

You can now import the Algolia API client in your project and play with it.

import { algoliasearch } from 'algoliasearch';

// Instantiate the client
const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');

// Add a new record to your Algolia index
const { taskID } = await client.saveObject({
indexName: '<YOUR_INDEX_NAME>',
body: {
title: 'My Algolia Object',
},
});

// Poll the task status to know when it has been indexed
await client.waitForTask({ indexName: '<YOUR_INDEX_NAME>', taskID });

// Fetch search results
const { results } = await client.search({
requests: [
{
indexName: '<YOUR_INDEX_NAME>',
// You can make typos, we handle it
query: 'my aloglia ojbect',
hitsPerPage: 50,
},
],
});

console.log('[Results]', results);

Advanced use cases

If you don’t find a use case that suits your needs, please request it.

You can learn more on how to use Algolia in your project by reading our dedicated guides for advanced use cases.