RESTful API documentation.

292 views
Skip to first unread message

Adam Holden

unread,
Feb 20, 2014, 2:41:37 PM2/20/14
to anki-syn...@googlegroups.com
I am having a hard time finding any information about how the RESTful API works.
I know in a post from you on here a few months back you said it was in the works, but I have not been able to find anything.
Where does that exist? If it does not, is there an estimate of when this will be available?

David Snopek

unread,
Feb 21, 2014, 8:14:57 AM2/21/14
to anki-syn...@googlegroups.com
Hi Adam,

Unfortunately, there still isn't complete documentation for the API. :-/ Lately, I haven't had a lot of time for this project.

However, I can give you a super quick overview and explain how to gleen more information from the code! If you would be willing to help create documentation as you learn the API, that would be awesome. :-) If you're interested in doing that, you can just start editting the Wiki on GitHub:


All the code for the API and be found in this file:


All of the endpoints take HTTP POST requests and accept/return JSON (except for the top-level URL, which is a GET request and returns text with version information). So, the API is actually not quite RESTful, it's more like a super simple HTTP RPC.

There is one magic URL, /list_collections which returns the names of all available collections. Every other URL will contain the collection name and is directly connected to a Handler class:

/collection/[NAME]/[METHOD] -> CollectionHandler
/collection/[NAME]/model/[MODEL_ID]/[METHOD] -> ModelHandler
/collection/[NAME]/note/[NOTE_ID]/[METHOD] -> NoteHandler
/collection/[NAME]/deck/[DECK_ID]/[METHOD] -> DeckHandler
/collection/[NAME]/card/[CARD_ID]/[METHOD] -> CardHandler

Replace [NAME] with the collection name and [METHOD] with a paricular method on the Handler class that you want to call. So, for example, POSTing to this URL: 

/collection/mine/latest_notes

... will call the CollectionHandler.latest_notes() method in the rest_app.py file I linked above.

Unfortunately, right now, the only way to find out what arguments each method takes is by looking at the code. But all the methods are pretty short and *usually* are just stubs that call a similarly named function in Anki.

If you want to help by documenting the methods as you learn how they work, please update this page in the Wiki:


I hope that helps and thanks in advance for any help!

Best regards,
David.


--
You received this message because you are subscribed to the Google Groups "Anki Sync Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to anki-sync-serv...@googlegroups.com.
To post to this group, send email to anki-syn...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/anki-sync-server/63e4d2aa-650e-4910-886f-c80abefe55cb%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Adam Holden

unread,
Feb 21, 2014, 12:49:23 PM2/21/14
to anki-syn...@googlegroups.com
Ah, sorry for being blind, I'm still pretty new to GitHub and didn't see the wiki link.

Thanks for the reply I will definitely take a look.


--
You received this message because you are subscribed to a topic in the Google Groups "Anki Sync Server" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/anki-sync-server/MgZ8o-8Mcpo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to anki-sync-serv...@googlegroups.com.

To post to this group, send email to anki-syn...@googlegroups.com.

David Snopek

unread,
Feb 21, 2014, 12:58:31 PM2/21/14
to anki-syn...@googlegroups.com
Actually, you didn't miss anything! I created the wiki page this morning in response to your e-mail. :-) I really hope that will help to expand on the information there.

Best regards,
David.


Stephen Pierce

unread,
May 7, 2015, 3:15:18 PM5/7/15
to anki-syn...@googlegroups.com
Hi,

I'd like to create a php clone of your project, but I'm kind of running into a wall.  I haven't been able to get your project or the anki project to run from Eclipse.  Basically I'm just trying to figure out how the api works, what anki sends out and what the server responds with.  I noticed in an issue post you said you haven't been able to keep up with the api changes to anki and that the bundled copy of anki should be used.  I you can point me in the direction of how you reverse engineered the api, I could look at making some updates.  I'll also go through what you mentioned above and try to add to the restful documentation.

Thanks.

David Snopek

unread,
May 8, 2015, 8:45:46 AM5/8/15
to anki-syn...@googlegroups.com
Hi Stephen,

Actually, you shouldn't need to make a PHP clone - you can just talk to the API provided by AnkiServer from PHP. Personally, I built the web part of my application in PHP (for Drupal):


So, all you need to do is get the AnkiServer to run on your system. And then you can look at my PHP code for some inspiration on how to communicate with it.

As far as updating AnkiServer to work with newer versions of Anki:

I noticed in an issue post you said you haven't been able to keep up with the api changes to anki and that the bundled copy of anki should be used.  I you can point me in the direction of how you reverse engineered the api, I could look at making some updates.

So, this isn't a very exciting answer, but I basically just read the code. :-) Then to test if I was correct about how it worked, I wrote little Python scripts that called into the Anki APIs and tried to use them.
 
  I'll also go through what you mentioned above and try to add to the restful documentation.

That would be really awesome!

Thanks,
David.

Reply all
Reply to author
Forward
0 new messages