Creating Notebooks
How to create a new notebook using the Evernote API.
Creating a notebook is quite simple, really. You need only create an instance of the Notebook type, assign a value to its name member variable and pass it, in addition to a valid authentication token or developer token, as a parameter to NoteStore.createNotebook [1]:
#!/usr/bin/env python
import evernote.edam.type.ttypes as Types
from evernote.api.client import EvernoteClient
def getNonEmptyUserInput(prompt):
"Prompt the user for input, disallowing empty responses"
uinput = raw_input(prompt)
if uinput:
return uinput
print "This can't be empty. Try again."
return getNonEmptyUserInput(prompt)
auth_token = "" # set this to your dev token to avoid being prompted
if not auth_token:
auth_token = getNonEmptyUserInput("Enter your developer token: ")
client = EvernoteClient(token=auth_token, sandbox=True)
note_store = client.get_note_store()
##
# Create a new notebook
##
notebook = Types.Notebook()
notebook.name = "Example Notebook"
notebook = note_store.createNotebook(notebook)
print "New notebook created with GUID: %s" % notebook.guidThere are a few other (optional) members of Notebook that you might choose to set before calling createNotebook:
defaultNotebookis a boolean value which indicates whether or not this notebook is the default notebook in the user’s account.stackdescribes the name, as a string, of the notebook stack to which this notebook will be added.
Several other member variables are part of the Notebook type, but many of them are set automatically by the Evernote service when the notebook is created or are simply outside the scope of this document. Read the documentation on the Notebook type for additional information.
-
Note that some of our SDKs abstract away the need for an authentication token with requests like
NoteStore.createNotebook, so while this parameter is described in the API documentation, it may not be required. ↩