Radio TukTuk Radio TukTuk - 1 year ago 43
Ruby Question

Not able to create notebook and transfer files in evernote

I am developing a web application and I need to create an EverNote notebook and transfer some files in it.

I am able to authenticate user from EverNote but not able to create notebook. I'm also confused how to transfer files in that notebook.

Here is the authentication code. API URL

For creating a notebook:

noteStore.createNotebook(access_token.token, "my_notebook")


An error occurred: undefined method `write' for "my_notebook":String


following seth's lead

notebook = = "my_notebook3"
x= noteStore.createNotebook(access_token.token, notebook)
note =
note.notebookGuid = x.guid
note.title="my note"

working on file transfer in that note.

Answer Source

The second parameter is a Notebook structure, not a string. You need to do something like:

notebook = = "my_notebook"
noteStore.createNotebook(access_token.token, notebook)

Evernote notebooks contain only Notes, and Notes can have files attached to them. To attach a file to a new note, you need to create a Resource and include it in the note:

filename = # the file that you want to attach
image =, "rb") { |io| }
hashFunc =
hashHex = hashFunc.hexdigest(image)

data =
data.size = image.size
data.bodyHash = hashHex
data.body = image

resource =
resource.mime = # the appropriate MIME type = data
resource.attributes =
resource.attributes.fileName = filename

note =
note.title = "Title"
note.content = '<?xml version="1.0" encoding="UTF-8"?>' +
  '<!DOCTYPE en-note SYSTEM "">' +
  '<en-note>' +
  '<en-media type="' + resource.mime + '" hash="' + hashHex + '"/>' +
note.resources = [ resource ]

createdNote = noteStore.createNote(authToken, note)

The sample code in the Evernote API ZIP file demonstrates this. You can download the ZIP from