"Not enough rights to add an object" error while implementing Algolia
Asked Answered
B

3

24

I'm trying to index contacts in Algolia.
Here is my code:

StreamReader re = File.OpenText("contacts.json");
JsonTextReader reader = new JsonTextReader(re);`
JArray batch = JArray.Load(reader);
// Add objects 
Index index = client.InitIndex("contacts");

index.AddObjects(batch);

I'm getting an error on the last line:

Not enough rights to add an object
Broncobuster answered 28/4, 2016 at 13:7 Comment(4)
You should first read [How to ask [on StackOverflow]](stackoverflow.com/help/how-to-ask).Bronchopneumonia
About your specific error, it seems like the API key you're using doesn't allow you to index objects.Bronchopneumonia
@Bronchopneumonia I will improve my "asking question skill" for sure. Apparently the key i used was just for searching. I used admin key and it worked fine. Thanks a lot.Broncobuster
I'll just post this as an answer so that we can close the question.Bronchopneumonia
B
62

It seems like you're using an API key that doesn't have the "Add records" ACL in Algolia.

You probably used your search API key, when you want to use an API key with write permission to your index, e.g. your Admin API key.

Bronchopneumonia answered 29/4, 2016 at 9:5 Comment(2)
Admin API Key is used for "Add/Update" Index Operations, So use that.Bench
Creating a custom API keys with write ACLs (addObject, deleteObject, settings, editSettings + read ones search, browse + any you see fit) with a restriction to a subset of indices is a good idea in case you were to accidentally leak a key so that it doesn't impact your other apps using Algolia if you have any.Bronchopneumonia
D
5

You can create a new API Key and give it specific permissions, to search and addObjects in the ACL input field. You can create a new API Key in your Dashboard when selecting 'ALL API Keys'.

Algolia recommends to use your admin key only for backend search and create a new key for frontend search.

Here is some supporting documentation from Algolia https://www.algolia.com/doc/guides/security/api-keys/#rights-and-restrictions

Dramatist answered 25/11, 2019 at 20:23 Comment(0)
S
4

I was getting this error because I was using the Search API in Firebase when using the Algolia extension. It's weird because there it says "Do not use the Admin API key" but guess what, the Admin key is the one that works...

Slapjack answered 21/6, 2021 at 15:9 Comment(1)
Using Admin API Key is not a good solution. Instead, you can create a new API key and set access.Metrics

© 2022 - 2024 — McMap. All rights reserved.