The most basic Evernote note will contain only text. They can get much more complex than that, of course, but we need to crawl before we can walk.
Prerequisites
To proceed with this example, we’ll assume that the following are already in place:
- You have a developer token (or a working OAuth implementation by which you can retrieve a valid authentication token)
- You have an instance of UserStore and NoteStore
Creating notes in Evernote is done using the NoteStore.createNote
API function. This function takes two arguments: a valid auth token (as a string) and an instance of Types.Note
. The Note
instance, in turn, will need to have the following attributes defined at minimum before we can send it to the API:
Note.title
— the title of the noteNote.content
— the body of the note, formatted as ENML (Evernote Markup Language)
Optionally, we can also set the GUID of the notebook where we’d like this note to reside (as Note.notebookGuid
). If we don’t provide this value, the note will be created in the account’s default notebook.
Each note’s body must begin with two things: the standard XML version declaration and the link to the ENML DOCTYPE definition for Evernote notes.
The XML version declaration will look like this:
<?xml version="1.0" encoding="UTF-8"?>
The ENML DOCTYPE definition (DTD) for notes will look like this:
<!DOCTYPE en-note SYSTEM "https://xml.evernote.com/pub/enml2.dtd">
If either of these nodes is omitted in the note body, the Evernote API will reject the note as malformed and invalid.
Assuming both of those pieces are in place, now we just need to add the body of the note, which must be wrapped in <en-note>
tags. Here is the body of a simple (yet complete) Evernote note:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "https://xml.evernote.com/pub/enml2.dtd">
<en-note>Hello, world!</en-note>
If we take the above XML and a title, we have the necessary parts to create a very simple text note.
Below you’ll find sample code that performs the entire note creation process.