We are Borg
We are Borg

Reputation: 5311

Java, Evernote : Searching notes by self-assigned ID

I am working on a Java project where I am integrating Evernote services. Right now, I am able to save, update notes, but what I would like to do is to search notes. Now, As evernote is tied to our infrastructure, I would like to save an ID of the object whose text we are copying to Evernote.

So, whenever the text is updated, I would like to get the same Note from Evernote and update it's contents. These are the two problems I am facing :

  1. Saving our Primary key ID in Note object. Tried it with GUID, it gets saved as I can see the note in Sandbox, but have no idea how to search notes with GUID. If GUID shouldn't be the way, then where to save the primary key which is searchable.
  2. As mentioned in first point, which attribute or variable should be set which can be searchable.

Here is some of the saving and searching code I have so far :

Note note = new Note();
note.setTitle("New title");

String nBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
nBody += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">";
nBody += "<en-note>" + "Test" + "</en-note>";
note.setContent(nBody);
note.setGuid("1234");

Note savedNote =   noteStoreClient.createNote(note);

Search code :

NoteFilter noteFilter = new NoteFilter();
// AS you can see, I have no idea what filter to set here. 
//  noteFilter.getTagGuids(id);

NoteList noteList = noteStoreClient.findNotes(noteFilter,0,100);

List<Note> notes = noteList.getNotes();

for(Note note : notes){
    System.out.println("Note title is "+note.getTitle());
}

Kindly let me know what I can do. Thanks a lot. :-)

Udpate

This happens when I try to save the GUID with my own randomly created one. Error log :

EDAMUserException(errorCode:BAD_DATA_FORMAT, parameter:Note.guid)

      at com.evernote.edam.notestore.NoteStore$getNote_result.read(NoteStore.java:13514)

      at com.evernote.edam.notestore.NoteStore$Client.recv_getNote(NoteStore.java:1346)

      at com.evernote.edam.notestore.NoteStore$Client.getNote(NoteStore.java:1316)

      at com.evernote.clients.NoteStoreClient.getNote(NoteStoreClient.java:368)

      at com.journaldev.spring.service.EvernoteServiceImpl.findNoteById(EvernoteServiceImpl.java:157)

Upvotes: 1

Views: 133

Answers (1)

akhaku
akhaku

Reputation: 1157

You can't set a manually assigned guid on a note when creating it - guids are assigned by the service and returned on the Note object as part of the createNote call on NoteStore.

As an aside, guids have a certain format, see the format here.

Upvotes: 2

Related Questions