(Java API) Support for finding/deleting notes

(Regards this API api/src/main/java/com/ichi2/anki/api/AddContentApi.kt and Third Party Apps · ankidroid/Anki-Android Wiki · GitHub)

Right now, editing existing notes through the AnkiDroid API isn’t very practical. You can update notes if you have their noteId, but that means third-party apps have to keep track of all those IDs themselves - which is pretty inconvenient and easy to mess up.
It’d be a lot easier if the API let you search for notes based on field content (like the front of the card) to get the noteId when needed. Also, some way to delete notes through the API would be also good, but I guess this would be a bit sensitive.

3 Likes

I ran into the same issue (deleting) and wanted to find some answers before coding it myself, so I found your post… then coded it myself :slight_smile:

Deleting is definitely supported, and I suspect the search too.
You have to implement it yourself, and sadly… you can’t use the existing class.

You can wrap it, implement the rest, and you may want to compromise (I won’t be doing compat for old versions etc.)

Here it is for deleting: Android-HSKFlashcardsWidget/app/src/main/java/fr/berliat/hskwidget/data/dao/AnkiNotesDAO.kt at master · licryle/Android-HSKFlashcardsWidget · GitHub

The reference in Anki’s code is here: Anki-Android/api/src/main/java/com/ichi2/anki/api/AddContentApi.kt at main · ankidroid/Anki-Android · GitHub

Note that deleting works but crashes Anki when opening the UI. Filed here: Anki-Android/issues/18294

I realized I pasted one of the wrong links – this is better to study available APIs.

Check out the functions:
fun update
fun insert
fun query
fun delete

Would this allow for editing a note’s fields within a card template? Trying to figure out how to with the API.

Edit:
Apologies, got this mixed up with the javascript api.