Reputation: 1
In my backend I would like to refresh an Algolia search index (clear, update, delete) using the Javascript API client. https://www.algolia.com/doc/api-client/javascript/manage-indices/
I can access the respective index and search works. However, listIndexes and all kind of index manipulations do not work. Any idea what I overlooked (relatively new to Algolia API)?
<script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js"></script>
<script>
$( document ).ready(function() {
console.log( "ready!" );
var client = algoliasearch('XXXX', 'YYYY');
var index = client.initIndex('rd_showcase');
// index search works
index.search('image', function(err, content) {
console.log(content.hits);
console.log("search for image done");
});
index.search('image', function searchDone(err, content) {
console.log(err, content);
});
// error: 403 forbidden
/*
client.listIndexes(function(err, content) {
console.log(content);
});
*/
// error: 400 bad request
client.copyIndex('rd_showcase', 'rd_showcase_20170212', function(err, content) {
console.log(content);
});
});
</script>
Upvotes: 0
Views: 1232
Reputation: 705
From the code you posted here I can see you want to do it from the front-end JS code - anybody with access to website can read the code.
For security reasons the data manipulation methods are disabled to be used from front end code. Those operations require Admin API key for data manipulation and it's a security issue to show your Admin API key to anyone with access to the website.
To perform clear
, listIndices
and other data sensitive operations, you'll need to do it from backend / server side. If you want to use JavaScript you might use Node.js. If you don't care about the language you can use any other server-side lang like PHP, Ruby, Java, ...
Upvotes: 1