Evernote API
Documents & ProductivityEvernote Public API Documentation
Evernote offers public APIs that allow developers to create applications that can access and manipulate Evernote data. The Evernote Development Center provides comprehensive documentation for these APIs, including sample codes in different programming languages like JavaScript.
Getting Started with Evernote API
Before writing code to access Evernote, you must have Evernote API key and token. All the API details are available on https://dev.evernote.com/doc/.
To get started, you need to:
- Sign up for an Evernote account
- Register your application in the Evernote developer center
- Request access to user accounts
- Obtain OAuth authentication details
JavaScript API Examples
Below are some of the most common Evernote API calls in JavaScript:
Authentication
const consumerKey = ''; // Evernote API Consumer Key
const consumerSecret = ''; // Evernote API Consumer Secret
const oauth = new OAuth(Evernote.oauthRequestTokenUrl(),
Evernote.oauthAccessTokenUrl(),
consumerKey,
consumerSecret,
'1.0',
null,
'HMAC-SHA1'
);
oauth.setAccessToken(token, secret);
This code snippet sets up access to the Evernote API using OAuth.
Creating a Note
const noteStore = client.getNoteStore();
const note = new Evernote.Note();
note.title = "New Note";
note.content = '<?xml version="1.0" encoding="UTF-8"?>' +
'<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' +
'<en-note>Hello, world!</en-note>';
noteStore.createNote(authToken, note, function(err, note) {
if (err) {
console.log(err);
}
});
This code snippet creates a new Evernote note.
Retrieving Notebook List
const noteStore = client.getNoteStore();
noteStore.listNotebooks(authToken, function (err, notebooks) {
if (err) {
console.log(err);
}
else {
for (let i in notebooks) {
console.log(notebooks[i].name);
}
}
});
This code snippet retrieves a list of notebooks.
Searching Notes
const filter = new Evernote.NoteFilter();
filter.words = "search keyword";
const offset = 0;
const maxNotes = 20;
const spec = new Evernote.NotesMetadataResultSpec({
includeTitle: true,
includeUpdated: true,
includeAttribute: true,
includeTagGuids: true,
includeContentLength: true
});
noteStore.findNotesMetadata(filter, offset, maxNotes, spec, function (err, noteList) {
if (err) {
console.log(err);
}
else {
console.log(noteList);
}
});
This code snippet searches for notes based on a specific keyword.
Updating a Note
const noteStore = client.getNoteStore();
const note = new Evernote.Note();
noteStore.getNote(authToken, noteId, true, false, false, false, function (err, note) {
if (err) {
console.log(err);
}
else {
note.title = "Updated Title";
note.content = '<?xml version="1.0" encoding="UTF-8"?>' +
'<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' +
'<en-note>Hello, updated world!</en-note>';
noteStore.updateNote(authToken, note, function(err, note) {
if (err) {
console.log(err);
}
else {
console.log(note);
}
});
}
});
This code snippet updates an Evernote note.
Conclusion
The Evernote Public API provides developers with the tools to easily integrate Evernote capabilities into their own applications. By using JavaScript, developers can take advantage of the powerful Evernote API functions to build innovative, cross-platform applications.