JavaScript API client FAQ
On this page
- 1. Why am I getting âImpossible to connectâ, âUnable to connectâ, or âUnreachable hostsâ errors?
- 2. How can I stay up-to-date with new major versions of the API clients?
- 3. Why am I getting the âRecord at the position XX objectID=XX is too bigâ error?
- 4. Why canât I find the object with the findObject method?
- 5. Why canât I use the generateSecuredApiKey method without restrictions?
- 6. Why does the replaceAllObjects method hang forever?
- 7. Why doesnât replaceAllObjects replace all the objects and leave a temporary index?
- 8. When using replaceAllObjects, why does the destination index contains fewer records than expected?
- 9. How to delete objects without their objectIDs?
- 10. Why is there a Cross-Origin Resource Sharing (CORS) error?
- 11. Why am I getting âUnable to connectâ or âUnreachable hostsâ errors when using Algolia with Google Firebase?
- 12. Why am I getting the âinitPlaces is not a functionâ error?
- 13. Why am I getting the âUnhandledPromiseRejectionWarning: Unhandled promise rejectionâ error?
- 14. Why do I get ââcreateHmacâ is not exportedâ error when bundling
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
Why am I getting âImpossible to connectâ, âUnable to connectâ, or âUnreachable hostsâ errors?
If youâre facing connectivity issues, here are some checks you should perform on your side before contacting our support team:
- Are you using the correct application ID and API key? You can find these credentials on your Algolia dashboard.
- Did anything recently change in your code or on your data center providerâs side? Make sure to check their status too.
- Using Firebase? The Firebase free plan only allows requests to other Google APIs. Because of this limitation, you can only use Algolia with Firebase if youâre on a paid Firebase tier.
If youâre unable to debug the problem yourself, contact the Algolia support team with the following information:
- API client and version (e.g., JavaScript API client 4.3.0)
- Language and version (e.g., PHP 7.1)
- Code snippet to reproduce the issue
- Error message or stack trace (if applicable)
- The Algolia index name with which youâre experiencing issues
- The precise timeline (in the UTC time zone of the event)
- Having trouble connecting to the Algolia API from your servers? Send us the link generated by the diagnostic script command on your impacted servers:
Copy
1
curl -sL https://algolia.com/downloads/diag.sh > ./diag.sh && sudo ./diag.sh ApplicationID
Ensure that you replace âApplicationIDâ with your actual Algolia Application ID.
- Having trouble connecting to the Algolia API from your browser? Head over to community.algolia.com/diag/ and send us this output instead.
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
How can I stay up-to-date with new major versions of the API clients?
You can check out our changelog page.
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
Why am I getting the âRecord at the position XX objectID=XX is too bigâ error?
Youâre getting this error because thereâs a size limit for records. Make sure you reduce your records and try again.
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
Why canât I find the object with the findObject
method?
If you need to get an object from your index, you should use the getObjects
method.
You should only use findObject
to debug the relevance of a specific object, and in development mode. This method accepts a condition and returns the first matching object along with its position information in the result set. Note that the result set is limited to a certain amount of records, not the entire index.
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
Why canât I use the generateSecuredApiKey
method without restrictions?
You must add at least one restriction to generate a valid secured API key. If there are no restrictions, thereâs no point in hiding the original API key since the generated secured API key has the same permissions and constraints.
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
Why does the replaceAllObjects
method hang forever?
When an index doesnât exist, and youâre using the replaceAllObjects
with the safe
parameter, the method can get stuck and hang forever. This happens because the method expects the index to exist.
To fix this issue, you can either create the index using the Algolia dashboard, or with the API using an empty setSettings
.
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
Why doesnât replaceAllObjects
replace all the objects and leave a temporary index?
If youâve performed replaceAllObjects
, it may still be in progress. If you suspect that the operation didnât complete successfully and left a temporary index, make sure to double-check the number of records of the temporary index.
If the number of records of the temporary index doesnât change for 10 minutes, thereâs a chance the operation didnât finish because of an error while indexing records in the temporary index. To debug this, we recommend you check the logs in your Algolia dashboard for the temporary index and see if you find any errors.
Besides, you may also be able to debug the issue in your development console or logging platform.
If youâre unable to debug the problem yourself, contact the Algolia support team with the following information:
- API client and version (e.g., Go client 3.4.0)
- Language and version (e.g., Java 1.8)
- Code snippet to reproduce the issue
- Error message or stack trace (if applicable)
- The Algolia index name with which youâre experiencing issues
- The precise timeline (in the UTC time zone of the event)
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
When using replaceAllObjects
, why does the destination index contains fewer records than expected?
This issue may happen when indexing a large number of records, and because of the asynchronous nature of Algolia. You can fix this issue with the safe
parameter.
If you need to index many records, you may want to process replaceAllObjects
in the background, as the safe
parameter may cause the operation to take longer than expected.
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
How to delete objects without their objectID
s?
The most convenient way is to use the deleteBy
method, as it enables you to delete one or more objects based on filters (numeric, facet, tag or geo queries).
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
Why is there a Cross-Origin Resource Sharing (CORS) error?
The Algolia APIs support cross-origin requests. If youâre getting such an error when indexing or searching, first make sure that your application ID is correct. An incorrect application ID results in querying an endpoint that doesnât exist, thus resulting in the error.
If the issue persists despite correct credentials, contact the Algolia support team.
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
Why am I getting âUnable to connectâ or âUnreachable hostsâ errors when using Algolia with Google Firebase?
Are you using a Firebase free plan? Unfortunately, Firebaseâs free plan only allows for network requests to Google services. You can see it on their pricing page, under the Outbound networking section. This is the most common cause for this error.
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
Why am I getting the âinitPlaces
is not a functionâ error?
The initPlaces
method is no longer available. If you want to use this feature, we recommend you keep using v3, or consider using the following code:
Places is going away on May 31, 2022. Read the announcement.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import algoliasearch from 'algoliasearch/lite';
import { shuffle } from '@algolia/client-common';
const places = (appId = '', apiKey = '', options) => {
const placesClient = algoliasearch(appId, apiKey, {
hosts: [{ url: 'places-dsn.algolia.net' }].concat(
shuffle([
{ url: 'places-1.algolia.net' },
{ url: 'places-2.algolia.net' },
{ url: 'places-3.algolia.net' }
])
),
...options
});
return (query, requestOptions) => {
return placesClient.transporter.read(
{
method: 'POST',
path: '1/places/query',
data: {
query
},
cacheable: true
},
requestOptions
);
};
};
const search = places('YOUR_PLACES_APP_ID', 'YOUR_PLACES_API_KEY');
search('query string').then(results => {
console.log(results);
});
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
Why am I getting the âUnhandledPromiseRejectionWarning: Unhandled promise rejectionâ error?
In JavaScript, you must handle promise rejections. You can understand the error with a catch
block:
1
2
3
4
5
6
try {
// your async code
const results = await index.search('');
} catch (e) {
console.log(e);
}
Itâs recommended to use the Kotlin API client, which is better suited for Android development.
Why do I get ââcreateHmacâ is not exportedâ error when bundling
In Vite and some other bundlers, the crypto
module isnât polyfilled completely for browsers. This error means that createHmac
is used in code in the algoliasearch client. The function is used for the generateSecuredApiKey
server-only function.
In a production environment, this shouldnât happen, so double-check that you:
- Use
algoliasearch/lite
in browser environments - Set
browser: true
in module resolution