Anki public API

Are there any plans for a public API on AnkiWeb?

People are requesting a push cards to Anki feature on this website I’ve created—mylingua.world. It suggests Chinese content to language learners based on their interest and skill level. Being able to read this content and then pushing unknown words directly into Anki would be awesome.
Would also just try to reverse engineer the API the desktop is using but as far as I know that is kinda forbidden.

Thanks for your help.

2 Likes

No. API is not public and neither is AnkiWeb. Your best bet, and quite frankly better option, would be to allow users to download the deck as an APKG and then import it directly into Anki. That way user can then decide what they want to do with it, including uploading it to their AnkiWeb account on their own.

This is better because anki clients have backup system in case things go wrong. Editing their AnkiWeb directly would be super unsafe in case something goes wrong and users lose cards and stuff. Where to upload cards should be user choice.

Look into genanki python library to generate anki decks programmatically.

3 Likes

As AnkiWeb is a free service, I’m afraid I don’t currently want to deal with the potential performance issues and troubles a public API might cause.

4 Likes

The way to go seems to build a public API for some kind of intermediary online service (so that you can add notes without having the desktop Anki open), which will then sync with Anki using some addon. The big issue is matching up schemas, since Anki has infinite flexibility.

1 Like

Thank you. That’s what I thought, I’d have to do anyways. Do you know if there is any documentation on the APKG format out there? Couldn’t find anything in a quick search.

That’s what I thought. Thanks for having created this wonderful system Damien! :slight_smile:

1 Like

Uh nice, that is a very neat solution I haven’t thought of. Thanks a lot!

Not sure about that actually. But Look into genanki which can generate apkg decks. Looking into the code you can probably figure out how it’s done. @dae probably would have a better resource on the format specs.

1 Like

An apkg is basically an archive containing media files and a collection file, but there are some subtleties. So as an apkg uses the same structure as your local collection file, this document might interest you: Database Structure · ankidroid/Anki-Android Wiki · GitHub

1 Like

apkg files were never intended to be used by other programs. In the future we’d like to add a different file format that is easier for third-party programs to read/write.

2 Likes
  1. on your website, add a “add to anki” functionality, this simply marks the word in your internal database.
  2. develop an anki addon (specific to your website) to sync from your website to add those words into anki.

It would be difficult to directly add to anki in one step. Because people have their own note types, fields, decks, etc. Your website will simply be unaware and will have no way of knowing where and how the user wants to add that note. That logic is best handled in Anki.

Don’t be intimated by that second part. If you’re a developer, you can develop an Anki module, as simple as that.

1 Like

That’s good to know. For now, we’ll just work with apkg.

Yes, that’s what we are going to go for. Thanks a lot for this idea!

Very useful resource, thank you!