Returns information about the current card or `null` if not in review mode.
*Sample request*:
```json
{
"action": "guiCurrentCard",
"version": 6
}
```
*Sample result*:
```json
{
"result": {
"answer": "back content",
"question": "front content",
"deckName": "Default",
"modelName": "Basic",
"fieldOrder": 0,
"fields": {
"Front": {"value": "front content", "order": 0},
"Back": {"value": "back content", "order": 1}
},
"template": "Forward",
"cardId": 1498938915662,
"buttons": [1, 2, 3],
"nextReviews": ["<1m","<10m","4d"]
},
"error": null
}
```
***guiStartCardTimer**
Starts or resets the `timerStarted` value for the current card. This is useful for deferring the start time to when
it is displayed via the API, allowing the recorded time taken to answer the card to be more accurate when calling
`guiAnswerCard`.
*Sample request*:
```json
{
"action": "guiStartCardTimer",
"version": 6
}
```
*Sample result*:
```json
{
"result": true,
"error": null
}
```
***guiShowQuestion**
Shows question text for the current card; returns `true` if in review mode or `false` otherwise.
*Sample request*:
```json
{
"action": "guiShowQuestion",
"version": 6
}
```
*Sample result*:
```json
{
"result": true,
"error": null
}
```
***guiShowAnswer**
Shows answer text for the current card; returns `true` if in review mode or `false` otherwise.
*Sample request*:
```json
{
"action": "guiShowAnswer",
"version": 6
}
```
*Sample result*:
```json
{
"result": true,
"error": null
}
```
***guiAnswerCard**
Answers the current card; returns `true` if succeeded or `false` otherwise. Note that the answer for the current
card must be displayed before before any answer can be accepted by Anki.
*Sample request*:
```json
{
"action": "guiAnswerCard",
"version": 6,
"params": {
"ease": 1
}
}
```
*Sample result*:
```json
{
"result": true,
"error": null
}
```
***guiDeckOverview**
Opens the *Deck Overview* dialog for the deck with the given name; returns `true` if succeeded or `false` otherwise.
*Sample request*:
```json
{
"action": "guiDeckOverview",
"version": 6,
"params": {
"name": "Default"
}
}
```
*Sample result*:
```json
{
"result": true,
"error": null
}
```
***guiDeckBrowser**
Opens the *Deck Browser* dialog.
*Sample request*:
```json
{
"action": "guiDeckBrowser",
"version": 6
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
***guiDeckReview**
Starts review for the deck with the given name; returns `true` if succeeded or `false` otherwise.
*Sample request*:
```json
{
"action": "guiDeckReview",
"version": 6,
"params": {
"name": "Default"
}
}
```
*Sample result*:
```json
{
"result": true,
"error": null
}
```
***guiExitAnki**
Schedules a request to gracefully close Anki. This operation is asynchronous, so it will return immediately and
won't wait until the Anki process actually terminates.
*Sample request*:
```json
{
"action": "guiExitAnki",
"version": 6
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
#### Media Actions
***storeMediaFile**
Stores a file with the specified base64-encoded contents inside the media folder. Alternatively you can specify a
absolute file path, or a url from where the file shell be downloaded. If more than one of `data`, `path` and `url` are provided, the `data` field will be used first, then `path`, and finally `url`. To prevent Anki from removing files not used by any cards (e.g. for configuration files), prefix the filename with an underscore. These files are still synchronized to AnkiWeb.
Any existing file with the same name is deleted by default. Set `deleteExisting` to false to prevent that
by [letting Anki give the new file a non-conflicting name](https://github.com/ankitects/anki/blob/aeba725d3ea9628c73300648f748140db3fdd5ed/rslib/src/media/files.rs#L194).
*Sample request*:
```json
{
"action": "storeMediaFile",
"version": 6,
"params": {
"filename": "_hello.txt",
"data": "SGVsbG8sIHdvcmxkIQ=="
}
}
```
*Sample result*:
```json
{
"result": "_hello.txt",
"error": null
}
```
*Content of `_hello.txt`*:
```
Hello world!
```
*Sample request*:
```json
{
"action": "storeMediaFile",
"version": 6,
"params": {
"filename": "_hello.txt",
"path": "/path/to/file"
}
}
```
*Sample result*:
```json
{
"result": "_hello.txt",
"error": null
}
```
*Sample request*:
```json
{
"action": "storeMediaFile",
"version": 6,
"params": {
"filename": "_hello.txt",
"url": "https://url.to.file"
}
}
```
*Sample result*:
```json
{
"result": "_hello.txt",
"error": null
}
```
***retrieveMediaFile**
Retrieves the base64-encoded contents of the specified file, returning `false` if the file does not exist.
*Sample request*:
```json
{
"action": "retrieveMediaFile",
"version": 6,
"params": {
"filename": "_hello.txt"
}
}
```
*Sample result*:
```json
{
"result": "SGVsbG8sIHdvcmxkIQ==",
"error": null
}
```
***getMediaFilesNames**
Gets the names of media files matched the pattern. Returning all names by default.
*Sample request*:
```json
{
"action": "getMediaFilesNames",
"version": 6,
"params": {
"pattern": "_hell*.txt"
}
}
```
*Sample result*:
```json
{
"result": ["_hello.txt"],
"error": null
}
```
***deleteMediaFile**
Deletes the specified file inside the media folder.
*Sample request*:
```json
{
"action": "deleteMediaFile",
"version": 6,
"params": {
"filename": "_hello.txt"
}
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
#### Miscellaneous Actions
***requestPermission**
Request permission to use the API exposed by this plugin. Only request coming from origin listed in the
`webCorsOriginList` option are allowed to use the Api. Calling this method will display a popup asking the user
if he want to allow your origin to use the Api. This is the only method that can be called even if the origin of
the request isn't in the `webCorsOriginList` list. It also doesn't require the api key. Calling this method will
not display the popup if the origin is already trusted.
This should be the first call you make to make sure that your application and AnkiConnect are able to communicate
properly with each other. New versions of AnkiConnect are backwards compatible; as long as you are using actions
which are available in the reported AnkiConnect version or earlier, everything should work fine.
Exports a given deck in `.apkg` format. Returns `true` if successful or `false` otherwise. The optional property
`includeSched` (default is `false`) can be specified to include the cards' scheduling data.
*Sample request*:
```json
{
"action": "exportPackage",
"version": 6,
"params": {
"deck": "Default",
"path": "/data/Deck.apkg",
"includeSched": true
}
}
```
*Sample result*:
```json
{
"result": true,
"error": null
}
```
***importPackage**
Imports a file in `.apkg` format into the collection. Returns `true` if successful or `false` otherwise.
Note that the file path is relative to Anki's collection.media folder, not to the client.
*Sample request*:
```json
{
"action": "importPackage",
"version": 6,
"params": {
"path": "/data/Deck.apkg"
}
}
```
*Sample result*:
```json
{
"result": true,
"error": null
}
```
***reloadCollection**
Tells anki to reload all data from the database.
*Sample request*:
```json
{
"action": "reloadCollection",
"version": 6
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
#### Model Actions
***modelNames**
Gets the complete list of model names for the current user.
*Sample request*:
```json
{
"action": "modelNames",
"version": 6
}
```
*Sample result*:
```json
{
"result": ["Basic", "Basic (and reversed card)"],
"error": null
}
```
***modelNamesAndIds**
Gets the complete list of model names and their corresponding IDs for the current user.
*Sample request*:
```json
{
"action": "modelNamesAndIds",
"version": 6
}
```
*Sample result*:
```json
{
"result": {
"Basic": 1483883011648,
"Basic (and reversed card)": 1483883011644,
"Basic (optional reversed card)": 1483883011631,
"Cloze": 1483883011630
},
"error": null
}
```
***modelFieldNames**
Gets the complete list of field names for the provided model name.
*Sample request*:
```json
{
"action": "modelFieldNames",
"version": 6,
"params": {
"modelName": "Basic"
}
}
```
*Sample result*:
```json
{
"result": ["Front", "Back"],
"error": null
}
```
***modelFieldsOnTemplates**
Returns an object indicating the fields on the question and answer side of each card template for the given model
name. The question side is given first in each array.
*Sample request*:
```json
{
"action": "modelFieldsOnTemplates",
"version": 6,
"params": {
"modelName": "Basic (and reversed card)"
}
}
```
*Sample result*:
```json
{
"result": {
"Card 1": [["Front"], ["Back"]],
"Card 2": [["Back"], ["Front"]]
},
"error": null
}
```
***createModel**
Creates a new model to be used in Anki. User must provide the `modelName`, `inOrderFields` and `cardTemplates` to be
used in the model. There are optinal fields `css` and `isCloze`. If not specified, `css` will use the default Anki css and `isCloze` will be equal to `False`. If `isCloze` is `True` then model will be created as Cloze.
Optionally the `Name` field can be provided for each entry of `cardTemplates`. By default the
card names will be `Card 1`, `Card 2`, and so on.
*Sample request*
```json
{
"action": "createModel",
"version": 6,
"params": {
"modelName": "newModelName",
"inOrderFields": ["Field1", "Field2", "Field3"],
"css": "Optional CSS with default to builtin css",
Modify the templates of an existing model by name. Only specifies cards and specified sides will be modified.
If an existing card or side is not included in the request, it will be left unchanged.
*Sample request*:
```json
{
"action": "updateModelTemplates",
"version": 6,
"params": {
"model": {
"name": "Custom",
"templates": {
"Card 1": {
"Front": "{{Question}}?",
"Back": "{{Answer}}!"
}
}
}
}
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
***updateModelStyling**
Modify the CSS styling of an existing model by name.
*Sample request*:
```json
{
"action": "updateModelStyling",
"version": 6,
"params": {
"model": {
"name": "Custom",
"css": "p { color: blue; }"
}
}
}
```
*Sample result*:
```json
{
"result": null,
"error": null
}
```
***findAndReplaceInModels**
Find and replace string in existing model by model name. Customise to replace in front, back or css by setting to true/false.
*Sample request*:
```json
{
"action": "findAndReplaceInModels",
"version": 6,
"params": {
"model": {
"modelName": "",
"findText": "text_to_replace",
"replaceText": "replace_with_text",
"front": true,
"back": true,
"css": true
}
}
}
```
*Sample result*:
```json
{
"result": 1,
"error": null
}
```
#### Note Actions
***addNote**
Creates a note using the given deck and model, with the provided field values and tags. Returns the identifier of
the created note created on success, and `null` on failure.
AnkiConnect can download audio, video, and picture files and embed them in newly created notes. The corresponding `audio`, `video`, and `picture` note members are
optional and can be omitted. If you choose to include any of them, they should contain a single object or an array of objects
with the mandatory `filename` field and one of `data`, `path` or `url`. Refer to the documentation of `storeMediaFile` for an explanation of these fields.
The `skipHash` field can be optionally provided to skip the inclusion of files with an MD5 hash that matches the provided value.
This is useful for avoiding the saving of error pages and stub files.
The `fields` member is a list of fields that should play audio or video, or show a picture when the card is displayed in
Anki. The `allowDuplicate` member inside `options` group can be set to true to enable adding duplicate cards.
Normally duplicate cards can not be added and trigger exception.
The `duplicateScope` member inside `options` can be used to specify the scope for which duplicates are checked.
Accepts an array of objects which define parameters for candidate notes (see `addNote`) and returns an array of
booleans indicating whether or not the parameters at the corresponding index could be used to create a new note.
*Sample request*:
```json
{
"action": "canAddNotes",
"version": 6,
"params": {
"notes": [
{
"deckName": "Default",
"modelName": "Basic",
"fields": {
"Front": "front content",
"Back": "back content"
},
"tags": [
"yomichan"
]
}
]
}
}
```
*Sample result*:
```json
{
"result": [true],
"error": null
}
```
***updateNoteFields**
Modify the fields of an exist note. You can also include audio, video, or picture files which will be added to the note with an
optional `audio`, `video`, or `picture` property. Please see the documentation for `addNote` for an explanation of objects in the `audio`, `video`, or `picture` array.
Returns the unix time of the latest review for the given deck. 0 if no review has ever been made for the deck.
*Sample request*:
```json
{
"action": "getLatestReviewID",
"version": 6,
"params": {
"deck": "default"
}
}
```
*Sample result*:
```json
{
"result": 1594194095746,
"error": null
}
```
***insertReviews**
Inserts the given reviews into the database. Required format: list of 9-tuples `(reviewTime, cardID, usn, buttonPressed, newInterval, previousInterval, newFactor, reviewDuration, reviewType)`