Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@algolia/requester-common

algolia6.7mMIT4.24.0TypeScript support: included

Common interfaces for promise-based request libraries

readme

Algolia for JavaScript

The perfect starting point to integrate Algolia within your JavaScript project

NPM version NPM downloads jsDelivr Downloads License

DocumentationInstantSearchCommunity ForumStack OverflowReport a bugFAQSupport

Migration note from v3.x to v4.x

In February 2020, we released v4 of our JavaScript client. If you are using version 3.x of the client, read the migration guide to version 4.x. Version 3.x will no longer be under active development.

✨ Features

  • Thin & minimal low-level HTTP client to interact with Algolia's API
  • Works both on the browser and node.js
  • UMD compatible, you can use it with any module loader
  • Built with TypeScript

⏭ Next

The next branch hosts the code of the new major version (v5). This version is generated from the API Clients Automation monorepo which is where you can follow the development and make contributions.

💡 Getting Started

First, install Algolia JavaScript API Client via the npm package manager:

npm install algoliasearch

Then, create objects on your index:

const algoliasearch = require('algoliasearch');

const client = algoliasearch('YourApplicationID', 'YourAdminAPIKey');
const index = client.initIndex('your_index_name');

const objects = [
  {
    objectID: 1,
    name: 'Foo',
  },
];

index
  .saveObjects(objects)
  .then(({ objectIDs }) => {
    console.log(objectIDs);
  })
  .catch(err => {
    console.log(err);
  });

Finally, let's actually search using the search method:

index
  .search('Fo')
  .then(({ hits }) => {
    console.log(hits);
  })
  .catch(err => {
    console.log(err);
  });

For the full documentation, visit the online documentation.

❓ Troubleshooting

Encountering an issue? Before reaching out to support, we recommend heading to our FAQ where you will find answers for the most common issues and gotchas with the client.

📄 License

Algolia JavaScript API Client is an open-sourced software licensed under the MIT license.

changelog

v4.24.0

  • chore: release v4.24.0 (#1528) (9f8956c), closes #1528
  • chore: revert "chore: release v4.24.0 (#1528)" (#1531) (6a67e85), closes #1528 #1531
  • feat(types): add banners in renderingContent (#1522) (5828389), closes #1522
  • feat(types): add hide in renderingContent facet values (#1529) (ed320a8), closes #1529
  • feat(types): add missing virtual attribute to Index type (#1530) (ba2d858), closes #1530
  • fix(support): redirect to ticket link (#1527) (f73a86a), closes #1527

v4.23.3

  • fix(types): add serverTimeMS to search response (#1518) (a1d1707), closes #1518

v4.23.2

  • fix(recommend): only export default function (#1514) (4a04d8e), closes #1514

v4.23.1

  • fix(recommend): export recommend methods to use them in algoliasearch (#1512) (5fc5f4f), closes #1512

v4.23.0

  • feat(search): fetch recommendations directly from algoliasearch (#1509) (8087b28), closes #1509

v4.22.1

  • fix(recommend): update recommended-for-you model type (#1500) (f94ce64), closes #1500

v4.22.0

  • fix(recommend): update TrendingFacetHit facetValue type to string (#1498) (ac9d6e2), closes #1498

v4.21.1

  • fix(recommend): RecommendedForYouQuery userToken should be required (#1496) (d20b253), closes #1496

v4.21.0

  • feat(recommend): add recommended-for-you model (#1490) (004f033), closes #1490
  • fix(recommend): getTrendingFacets typing (#1494) (94b46b5), closes #1494
  • docs(readme): fix typo (#1486) (db9953c), closes #1486

v4.20.0

  • feat(search): add inference ACL to API key object (#1479) (3a95126), closes #1479

v4.19.1

  • fix(recommend): Add Type RecommendQueriesResponse from old MultipleQueriesResponse for recommend (#1472) (36285b2), closes #1472

v4.19.0

  • feat(abtests): add outlier count to variant response payload (#1467) (b88a726), closes #1467
  • feat(recommend): add "Looking Similar" model (#1469) (01eac7f), closes #1469

v4.18.0

  • fix(types): union SearchForFacetValuesResponse type for multipleQueries (#1460) (6a786f1), closes #1460
  • feat(cache-browser-local-storage): Implemented TTL support to cached items (#1457) (9092414), closes #1457

v4.17.2

  • fix(search): fix wait method for updateApiKey request (#1464) (edc629d), closes #1464
  • docs(SearchOptions): fix jsdoc of sortFacetValuesBy (#1463) (a4309c7), closes #1463

v4.17.1

  • fix(recommend): Align getRecommendations type with actual implementation (#1459) (d18391b), closes #1459

v4.17.0

  • feat: update ab test typing (#1455) (f53c72c), closes #1455
  • feat(fetch): remove mode option to rely on library's default (#1452) (67293e1), closes #1452
  • feat(neural): make eventSources nullable (#1453) (eacfca2), closes #1453

v4.16.0

  • feat(neuralsearch): adding the semanticSearch settings to client-search (#1450) (a478ffd), closes #1450
  • Fix for the redirect object in SearchResponse (#1443) (6b0685c), closes #1443

v4.15.0

  • feat: add mode to settings types (#1439) (89fd80e), closes #1439

v4.14.3

  • fix(recommend): remove unused trendingFacets props (#1433) (ffbfc05), closes #1433
  • fix(recommend): update trending facets query props (RECO-1184) (#1434) (913443f), closes #1434
  • docs: Fix incorrect property description (#1429) (ba59b68), closes #1429

v4.14.2

  • fix(types): add abTestID to SearchResponse (#1419) (05059f2), closes #1419

v4.14.1

  • fix(types): Updating searchoptions with explain attribute (#1415) (c46932e), closes #1415

v4.14.0

  • chore: mention next version in README (#1413) (100d180), closes #1413
  • feat(fetch-requester): add @algolia/requester-fetch (#1411) (7b62403), closes #1411

v4.13.1

v4.13.0

  • feat(recommend): Add trending types and methods (#1396) (6882ec8), closes #1396

v4.12.2

  • fix(types): allow mixed arrays in numeric and tag filters (#1395) (326c833), closes #1395
  • fix(types): updating reRankingApplyFilter type and adding new property to RankingInfo (#1394) (e8f08ed), closes #1394

v4.12.1

  • fix(types): allow mix of strings and arrays in facetFilters (#1384) (dfc2a09), closes #1384

v4.12.0

  • feat(types): add reranking engine settings to types (#1378) (e9c0f30), closes #1378
  • chore: clean up unused package and auto exports (#1315) (dfa7254), closes #1315
  • chore: Configure Renovate (#1304) (f75924d), closes #1304
  • chore: disable renovate until the test suite is less flaky (#1370) (8c8db3d), closes #1370

v4.11.0

  • fix(insideBoundingBox): allow strings (#1310) (87d5b0d), closes #1310
  • feat: add custom request function (#1312) (3cea192), closes #1312
  • feat(ts): document enableReRanking (#1306) (00ad924), closes #1306
  • docs(recommend): add TSDoc (#1305) (a5df2fb), closes #1305

v4.10.5

  • fix(recommend): prevent undefined threshold (#1300) (7d21d3c), closes #1300

v4.10.4

  • fix(recommend): expose correct key on window in umd (#1298) (169b12a), closes #1298

v4.10.3

  • fix(answers): omit original hits in response (#1293) (fb62b15), closes #1293
  • fix(facetOrdering): facetOrdering.facets, not .facet (d931976)

v4.10.2

  • fix(recommend): export method types (#1287) (95281fe), closes #1287
  • chore(release): force public access on npm release (#1288) (2fefd78), closes #1288

v4.10.0

The @algolia/client-recommendation is now deprecated, please use @algolia/client-personalization instead. If you were using initRecommendation from the algoliasearch package, please use initPersonalization instead.

  • feat(recommend): introduce Recommend API client (#1280) (97ebde6), closes #1280 #1278
  • feat(personalization): deprecate client-recommendation (#1278)
  • fix(rules): automaticOptionalFacetFilters type takes the same input as automaticFacetFilters (#1279) (831a3de), closes #1279

v4.9.3

  • fix(ts): make all keys in facetOrdering optional (d772f98)

v4.9.2

  • feat(ts): document renderingContent (#1273) (04f2a20), closes #1273
  • fix(api-keys): fix typing issues (#1270) (fec87a9), closes #1270

v4.9.1

  • fix(types): support facetQuery in MultipleQueriesQuery (#1267) (84355a9), closes #1267

v4.9.0

  • feat(dictionaries): adds methods and tests (#1253) (aed6554), closes #1253
  • feat(types): support type and facet in search methods (#1263) (54c1cb7), closes #1263
  • fix(findAnswers): omit removeWordsIfNoResults correctly (3aec216)

v4.8.6

  • fix(answers): rename params to searchParameters (#1256) (0229a12), closes #1256
  • fix(onSucess): correctly deprecate (c7d04ca)
  • fix(types): update FindAnswersOptions (#1258) (bdf67a5), closes #1258
  • refactor(retry): Spell success properly (#1254) (173f5f1), closes #1254

v4.8.5

v4.8.4

  • feat(ts): add decompoundQuery (#1240) (446c9a0), closes #1240
  • feat(ts): add the attributesToTransliterate setting (#1244) (b91c035), closes #1244

v4.8.3

  • fix(ts): correct type for listIndices response (#1236) (0bb6bba), closes #1236

v4.8.2

  • fix(findAnswers): fix typing (#1233) (a935d88), closes #1233
  • fix(ts): don't require every attribute to be highlighted (#1234) (4591d0e), closes #1234

v4.8.1

  • fix(ts): correct search response for facets_stats (#1229) (ac732d1), closes #1229

v4.8.0

  • feat(saveSynonyms): replaceExistingSynonyms -> clearExistingSynonyms (#1226) (2fcf485), closes #1226 #1224
  • fix(findAnswers): expose in lite version (#1227) (6cb1d0a), closes #1227

v4.7.0

  • feat(findAnswers): implement the new method (experimental) (#1219) (8d962ea), closes #1219
  • feat(analytics & recommendation): allow creation of clients (initAnalytics, initRecommendation) with their own credentials (#1223) (a7938b0)

v4.6.0

  • fix(node): allow passing requesterOptions (#1215) (4348b38), closes #1215
  • fix(node): reuse http agent across client (#1216) (f6e9e56), closes #1216
  • feat(client-search): add personalization field to RankingInfo (#1213) (50b78a3), closes #1213

v4.5.1

Fixed

  • avoid bundle-size increase by using a slightly older version of babel

v4.5.0

Added

  • introduce a new Hit type, returned from search operations (#1191)
  • Allow hosts array to also accept strings (#1189)

Fixed

  • add missing updatedAt attribute to client-analytics (#1186)
  • a/b test VariantResponse typing (#1185)
  • getObjects can also return null if an object is not existing (#1183)

v4.4.0

Added

  • Accept multiple objectIDs in a Rule promotion (#1156, #1155)
  • Accept a custom http(s) agent in createNodeHttpRequester (#1180)

v4.3.1

Added

  • Support to multiple conditions on query rules (#1171, #1174)

v4.3.0

Added

  • naturalLanguages option type (#1147)
  • shouldStop option to stop browse (#1029)
  • inner_queries property to getLogs response (#1109, #1166)
  • enablePersonalization option to type Settings (#1151)

Fixed

  • additional clear, delete & deleteObject types for the .batch method (#1149)
  • unhandled promise issue while using while using accountCopyIndex (#1154)
  • node requester unicode characters being corrupted on large responses (#1164)

v4.2.0

Added

  • Improved acl property type in GetApiKeyResponse and addApiKey function param (#1126)
  • Improved AnalyticsClientOptions property type region (#1085)
  • Responses types can now be mutated (#1068)

Fixed

v4.1.0

Added

  • Field filterPromotes in Rule type (#1013)
  • Method hasPendingMappings (#1024)

Fixed

  • Field abtests in GetAbTestsResponse type (#1012)
  • browse related methods not bubbling up errors as expected (#1042)
  • Header x-algolia-user-id is not allowed on browser env (#1023)

v4.0.3

Fixed

  • browseObjects missing cursor error (#1011)
  • browseSynonyms|browseRules giving just a maximum of 20 hits (#1011)
  • Node entry point not es6 compliant (#1005)

v4.0.2

Fixed

  • DOMException being thrown while instantiating browser local storage cache driver (#999)

v4.0.1

Fixed

  • Missing repository entry on package.json (#989)

v4.0.0