View Source AnkiConnect.Actions.Note (anki_connect v0.1.1)
Note actions.
All functions are delegated inside AnkiConnect
module, so you should import them from there.
Link to this section Summary
Functions
Creates a note using the given deck and model, with the provided field values and tags.
Creates multiple notes using the given deck and model, with the provided field values and tags.
Adds tags to notes by note ID.
Accepts an array of objects which define parameters for candidate notes (see AnkiConnect.Actions.Note.add_note/1
) and returns an array of booleans indicating whether or not the parameters at the corresponding index could be used to create a new note.
Clears all the unused tags in the notes for the current user.
Deletes notes with the given ids.
Returns an array of note IDs for a given query.
Get a note’s tags by note ID.
Gets the complete list of tags for the current user.
Returns a list of objects containing for each note ID the note fields, tags, note type and the cards belonging to the note.
Removes all the empty notes for the current user.
Remove tags from notes by note ID.
Replace tags in notes by note ID.
Replace tags in all the notes for the current user.
Modify the fields and/or tags of an existing note.
Modify the fields of an existing note.
Set a note’s tags by note ID.
Link to this section Functions
@spec add_note(%{note: AnkiConnect.Specs.NoteSpec.t()}) :: {:ok, integer()} | {:error, any()}
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 error on failure.
Refer to AnkiConnect.Specs.NoteSpec
for information about the note
key.
sample-param
Sample param:
%{
note: %{
deck_name: "Default",
model_name: "Basic",
fields: %{
Front: "front content",
Back: "back content"
},
options: %{
allow_duplicate: false,
duplicate_scope: "deck",
duplicate_scope_options: %{
deck_name: "Default",
check_children: false,
check_all_models: false
}
},
tags: ["yomichan"],
audio: [%{
url: "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji=猫&kana=ねこ",
filename: "yomichan_ねこ_猫.mp3",
skip_hash: "7e2c2f954ef6051373ba916f000168dc",
fields: ["Front"]
}],
video: [%{
url: "https://cdn.videvo.net/videvo_files/video/free/2015-06/small_watermarked/Contador_Glam_preview.mp4",
filename: "countdown.mp4",
skip_hash: "4117e8aab0d37534d9c8eac362388bbe",
fields: ["Back"]
}],
picture: [%{
url: "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/A_black_cat_named_Tilly.jpg/220px-A_black_cat_named_Tilly.jpg",
filename: "black_cat.jpg",
skip_hash: "8d6e4646dfae812bf39651b59d7429ce",
fields: ["Back"]
}]
}
}
sample-result
Sample result:
{:ok, 1496198395707}
@spec add_notes(%{notes: [AnkiConnect.Specs.NoteSpec.t()]}) :: {:ok, [integer() | nil]} | {:error, any()}
Creates multiple notes using the given deck and model, with the provided field values and tags.
Returns an array of identifiers of the created notes (notes that could not be created will have a nil
identifier).
Refer to AnkiConnect.Specs.NoteSpec
for information about the notes
list elements.
sample-param
Sample param:
%{
notes: [
%{
deck_name: "Default",
model_name: "Basic",
fields: %{
Front: "front content",
Back: "back content"
},
tags: [
"yomichan"
],
audio: [
%{
url: "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji=猫&kana=ねこ",
filename: "yomichan_ねこ_猫.mp3",
skip_hash: "7e2c2f954ef6051373ba916f000168dc",
fields: [
"Front"
]
}
],
video: [
%{
url: "https://cdn.videvo.net/videvo_files/video/free/2015-06/small_watermarked/Contador_Glam_preview.mp4",
filename: "countdown.mp4",
skip_hash: "4117e8aab0d37534d9c8eac362388bbe",
fields: [
"Back"
]
}
],
picture: [
%{
url: "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/A_black_cat_named_Tilly.jpg/220px-A_black_cat_named_Tilly.jpg",
filename: "black_cat.jpg",
skip_hash: "8d6e4646dfae812bf39651b59d7429ce",
fields: [
"Back"
]
}
]
}
]
}
sample-result
Sample result:
{:ok, [1496198395707, nil]}
Adds tags to notes by note ID.
sample-param
Sample param:
%{
notes: [1483959289817, 1483959291695],
tags: "european-languages"
}
sample-result
Sample result:
{:ok, nil}
@spec can_add_notes(%{notes: [AnkiConnect.Specs.NoteSpec.t()]}) :: {:ok, [boolean()]} | {:error, any()}
Accepts an array of objects which define parameters for candidate notes (see AnkiConnect.Actions.Note.add_note/1
) 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-param
Sample param:
%{
notes: [
{
deck_name: "Default",
model_name: "Basic",
fields: {
Front: "front content",
Back: "back content"
},
tags: [
"yomichan"
]
}
]
}
sample-result
Sample result:
{:ok, [true]}
@spec clear_unused_tags() :: {:ok, nil} | {:error, any()}
Clears all the unused tags in the notes for the current user.
Deletes notes with the given ids.
If a note has several cards associated with it, all associated cards will be deleted.
sample-param
Sample param:
%{
notes: [1502298033753]
}
Returns an array of note IDs for a given query.
Query syntax is documented here.
sample-param
Sample param:
%{
query: "deck:current"
}
sample-result
Sample result:
{:ok, [1494723142483, 1494703460437, 1494703479525]}
Get a note’s tags by note ID.
sample-param
Sample param:
%{
note: 1483959289817
}
sample-result
Sample result:
{:ok, ["european-languages"]}
Gets the complete list of tags for the current user.
sample-result
Sample result:
{:ok, ["european-languages", "idioms"]}
Returns a list of objects containing for each note ID the note fields, tags, note type and the cards belonging to the note.
sample-param
Sample param:
%{
notes: [1502298033753]
}
sample-result
Sample result:
[
{
"noteId": 1502298033753,
"modelName": "Basic",
"tags": ["tag","another_tag"],
"fields": {
"Front": {"value": "front content", "order": 0},
"Back": {"value": "back content", "order": 1}
}
}
]
Removes all the empty notes for the current user.
Remove tags from notes by note ID.
sample-param
Sample param:
%{
notes: [1483959289817, 1483959291695],
tags: "european-languages"
}
sample-result
Sample result:
{:ok, nil}
@spec replace_tags(%{ notes: [integer()], tag_to_replace: String.t(), replace_with_tag: String.t() }) :: {:ok, nil} | {:error, any()}
Replace tags in notes by note ID.
sample-param
Sample param:
%{
notes: [1483959289817, 1483959291695],
tag_to_replace: "european-languages",
replace_with_tag: "french-languages"
}
@spec replace_tags_in_all_notes(%{ tag_to_replace: String.t(), replace_with_tag: String.t() }) :: {:ok, nil} | {:error, any()}
Replace tags in all the notes for the current user.
sample-param
Sample param:
%{
tag_to_replace: "european-languages",
replace_with_tag: "french-languages"
}
@spec update_note(%{note: AnkiConnect.Specs.NoteSpec.t()}) :: {:ok, nil} | {:error, any()}
Modify the fields and/or tags of an existing note.
In other words, combines update_note_fields
and update_note_tags
.
Please see their documentation for an explanation of all properties.
Either fields or tags property can be omitted without affecting the other. Thus valid requests to update_note_fields
also work with update_note
. The note must have the fields
property in order to update the optional audio, video, or picture objects.
If neither fields
nor tags
are provided, the method will fail. Fields are updated first and are not rolled back if updating tags fails. Tags are not updated if updating fields fails.
Warning: You must not be viewing the note that you are updating on your Anki browser, otherwise the fields will not update. See this issue for further details.
sample-param
Sample param:
%{
note: {
id: 1514547547030,
fields: {
Front: "new front content",
Back: "new back content"
},
tags: ["new", "tags"]
}
}
sample-result
Sample result:
{:ok, nil}
@spec update_note_fields(%{note: AnkiConnect.Specs.NoteSpec.t()}) :: {:ok, nil} | {:error, any()}
Modify the fields of an existing 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 add_note
for an explanation of objects in the audio
, video
, or pictur
e array.
Warning: You must not be viewing the note that you are updating on your Anki browser, otherwise the fields will not update. See this issue for further details.
sample-param
Sample param:
%{
note: {
id: 1514547547030,
fields: {
Front: "new front content",
Back: "new back content"
},
audio: [{
url: "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji=猫&kana=ねこ",
filename: "yomichan_ねこ_猫.mp3",
skipHash: "7e2c2f954ef6051373ba916f000168dc",
fields: [
"Front"
]
}]
}
}
sample-result
Sample result:
{:ok, nil}
Set a note’s tags by note ID.
Old tags will be removed.
sample-param
Sample param:
%{
note: 1483959289817,
tags: ["european-languages"]
}
sample-result
Sample result:
{:ok, nil}