diff --git a/AnkiConnect.py b/AnkiConnect.py index 436c771..56465d4 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -424,6 +424,18 @@ class AnkiBridge: if not note.dupeOrEmpty(): return note + def updateNoteFields(self, params): + collection = self.collection() + if collection is None: + return + + note = collection.getNote(params['id']) + if note is None: + raise Exception("Failed to get note:{}".format(params['id'])) + for name, value in params['fields'].items(): + if name in note: + note[name] = value + note.flush() def addTags(self, notes, tags, add=True): self.startEditing() @@ -1023,6 +1035,9 @@ class AnkiConnect: return results + @webApi() + def updateNoteFields(self, note): + return self.anki.updateNoteFields(note) @webApi() def canAddNotes(self, notes): diff --git a/README.md b/README.md index 900b6b0..6e1c676 100644 --- a/README.md +++ b/README.md @@ -763,6 +763,38 @@ guarantee that your application continues to function properly in the future. } ``` +#### Note Modification #### + +* **updateNoteFields** + + Modify the fields of an exist note. + + *Sample request*: + ```json + { + "action": "updateNoteFields", + "version": 5, + "params": { + "note": { + "id": 1514547547030, + "fields": { + "Front": "new front content", + "Back": "new back content" + }, + } + } + } + ``` + + *Sample result*: + ```json + { + "result": null, + "error": null + } + ``` + + #### Note Tags #### * **addTags**