anki-connect/actions/miscellaneous.md
DegrangeM 9fec86f7fe
Add requestPermission API method (#255)
* Add requestPermission Api Method

* Add documentation about requestPermission method

* Update version documentation
2021-05-07 20:33:06 -07:00

4.5 KiB

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.

    Sample request:

    {
        "action": "requestPermission",
        "version": 6
    }
    

    Samples results:

    {
        "result": {
            "permission": "granted",
            "requireApiKey": false,
            "version": 6
        },
        "error": null
    }
    
    {
        "result": {
            "permission": "denied"
        },
        "error": null
    }
    
  • version

Gets the version of the API exposed by this plugin. Currently versions 1 through 6 are defined.

Sample request:

{
    "action": "version",
    "version": 6
}

Sample result:

{
    "result": 6,
    "error": null
}
  • sync

    Synchronizes the local Anki collections with AnkiWeb.

    Sample request:

    {
        "action": "sync",
        "version": 6
    }
    

    Sample result:

    {
        "result": null,
        "error": null
    }
    
  • getProfiles

    Retrieve the list of profiles.

    Sample request:

    {
        "action": "getProfiles",
        "version": 6
    }
    

    Sample result:

    {
        "result": ["User 1"],
        "error": null
    }
    
  • loadProfile

    Selects the profile specified in request.

    Sample request:

    {
        "action": "loadProfile",
        "params": {
            "name": "user1"
        },
        "version": 6
    }
    

    Sample result:

    {
        "result": true,
        "error": null
    }
    
  • multi

    Performs multiple actions in one request, returning an array with the response of each action (in the given order).

    Sample request:

    {
        "action": "multi",
        "version": 6,
        "params": {
            "actions": [
                {"action": "deckNames"},
                {
                    "action": "browse",
                    "params": {"query": "deck:current"}
                }
            ]
        }
    }
    

    Sample result:

    {
        "result": [
            {"result": "Default", "error": null},
            {"result": [1494723142483, 1494703460437, 1494703479525], "error": null}
        ],
        "error": null
    }
    
  • exportPackage

    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:

    {
        "action": "exportPackage",
        "version": 6,
        "params": {
            "deck": "Default",
            "path": "/data/Deck.apkg",
            "includeSched": true
        }
    }
    

    Sample result:

    {
        "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:

    {
        "action": "importPackage",
        "version": 6,
        "params": {
            "path": "/data/Deck.apkg"
        }
    }
    

    Sample result:

    {
        "result": true,
        "error": null
    }
    
  • reloadCollection

    Tells anki to reload all data from the database.

    Sample request:

    {
        "action": "reloadCollection",
        "version": 6
    }
    

    Sample result:

    {
        "result": null,
        "error": null
    }