This document summarizes the correct AnkiConnect API format for model template and styling updates, discovered during AnkiDAY implementation.
- AnkiConnect version: 6
- Tested with Anki 2.x
{
"action": "modelTemplates",
"version": 6,
"params": {
"modelName": "ModelName"
}
}Returns:
{
"result": {
"Card 1": {
"Front": "{{Front}}",
"Back": "{{Front}}<hr id=answer>{{Back}}"
}
},
"error": null
}{
"action": "updateModelTemplates",
"version": 6,
"params": {
"model": {
"name": "ModelName",
"templates": {
"Card 1": {
"Front": "{{Front}}",
"Back": "{{Front}}<hr id=answer>{{Back}}"
}
}
}
}
}Key differences:
- Read operation uses
modelNameparameter - Write operation uses nested
model.nameparameter - Write operation expects templates as nested object, not array
{
"action": "modelStyling",
"version": 6,
"params": {
"modelName": "ModelName"
}
}Returns:
{
"result": {
"css": ".card { font-size: 20px; }"
},
"error": null
}{
"action": "updateModelStyling",
"version": 6,
"params": {
"model": {
"name": "ModelName",
"css": ".card { font-size: 24px; }"
}
}
}Key differences:
- Read operation uses
modelNameparameter - Write operation uses nested
model.nameandmodel.cssparameters
- Parameter naming inconsistency: Read operations use
modelName, write operations usemodel.name - Template format conversion: Our internal format uses arrays with
qfmt/afmt, AnkiConnect expects object withFront/Back - Both operations return null on success: Check for
errorfield to detect failures
# Test styling update
curl -X POST -d '{"action": "updateModelStyling", "version": 6, "params": {"model": {"name": "BasicExt", "css": ".card { color: red; }"}}}' http://127.0.0.1:8765
# Test template update
curl -X POST -d '{"action": "updateModelTemplates", "version": 6, "params": {"model": {"name": "BasicExt", "templates": {"Card 1": {"Front": "{{Front}}", "Back": "{{Back}}"}}}}}' http://127.0.0.1:8765
# Verify changes
curl -X POST -d '{"action": "modelStyling", "version": 6, "params": {"modelName": "BasicExt"}}' http://127.0.0.1:8765
curl -X POST -d '{"action": "modelTemplates", "version": 6, "params": {"modelName": "BasicExt"}}' http://127.0.0.1:8765