Skip to content

RESTful API Documentation

Austin Almond edited this page May 16, 2017 · 29 revisions

Unfortunately, there still isn't complete documentation on using the RESTful API. However, here is a super quick overview with information about how to gleen more information.

Please edit this page and help improve it!

Overview

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

https://github.com/dsnopek/anki-sync-server/blob/master/AnkiServer/apps/rest_app.py

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.

Collections

list_models

Returns a list of all models in a collection

Request

No parameters.

Response

array of objects, each representing a model

find_model_by_name

Returns a model that matches the given name

Request:

Required parameters:
  • model (string)

Response

object, representing a model. If no model is found with the given name, an empty response will be sent.

find_notes

Finds a set of notes

Request:

Optional parameters:
  • query (string) (omitting this will return an empty array)
  • preload (boolean)

Response

array of objects, each representing a note.

latest_notes

TODO Description

Request:

Optional parameters:
  • updated_since(date)
  • limit (integer)
  • preload (boolean)

Response

TODO

add_note

TODO Description

Request:

Required parameters:
  • model (string)
Optional parameters:
  • fields (object)
  • tags (string)

Response

None

list_tags

list_models

Returns a list of all models in a collection

Request

No parameters.

Response

array of objects, each representing a model

list_decks

Returns a list of all decks in the collection.

Request

No parameters.

Response

array of objects, each representing a deck

select_deck

Switches to a deck specified by the given ID number or name.

Request

Required parameters:
  • deck (string or number)

Response

None

create_dynamic_deck

This will create a dynamic deck based on the given query. If a deck exists with the same name, the old deck will be cleared.

Request

Required parameters
Optional parameters
  • name(string) - defaults to "Custom Study Session"
  • query (string) - defaults to '' (TODO document query)
  • count (int) - default to 100
  • mode (string) - "random", "added", or "due". defaults to "random".

Response

Returns an object representing the newly created dynamic deck.

empty_dynamic_deck

TODO

find_cards

TODO

latest_cards

TODO

reset_scheduler

TODO

extend_scheduler_limits

TODO

next_card

TODO

answer_card

TODO

suspend_cards

TODO

unsuspend_cards

TODO

cards_recent_ease

TODO

latest_revlog

TODO

stats_report

TODO

set_language

TODO

Models

field_names

TODO

Notes

index

TODO

update

TODO

delete

TODO

add_tags

TODO

remove_tags

TODO

Decks

index

TODO

next_card

TODO

get_conf

TODO

set_update_conf

TODO

Cards

index

TODO

add_tags

TODO

remove_tags

TODO

stats_report

TODO

latest_revlog

TODO

Clone this wiki locally