mdbox
mdbox

Reputation: 412

Creating LinkedNotebooks from API

I am working with the Evernote api trying to make linked notebooks from within our web application.

We are using evernote-sdk-js version of the API.

We are able to create the Shared Notebook from the API. Also we are able to create a Linked Notebook and receive a valid response. The problem is the linked notebook is not working. The notebook is returned in the ListLinkedNotebook api call but when I try to authorize it I receive an error.

Error { identifier: 'SharedNotebook.id', key: 'xxxx' }

From what I've read means the notebook is no longer shared by the owner. This is not true as the owner account still shows the pending request in the 'share' window.

Here is the logical flow:

1) User enters email address of the person they wish to share notebook with. A request is made to our server to create a ShareNotebook.

We create a Shared Notebook like this: (From Owner Account)

  var notebook = new Evernote.SharedNotebook();
  notebook.notebookGuid = guid;
  notebook.email = email;
  notebook.privilege = Evernote.SharedNotebookPrivilegeLevel.FULL_ACCESS;

  var userclient = new Evernote.Client({token: token, sandbox: sandbox});
  var notestore = userclient.getNoteStore();
  notestore.createSharedNotebook(userclient.token, notebook, function(err, results){
      callback(err, results);
  });

With an example response like:

{
 allowPreview:null
 email:"[email protected]"
 id:12345
 notebookGuid:"d2fa3cbe-...."
 notebookModifiable:false
 privilege:4
 recipientSettings:null
 requireLogin:null
 serviceCreated:1469079222000
 serviceUpdated:1469079222000
 shareKey:"xxxx-sxxx"
 userId:999xxxxx
 username:null
}

2) Since Evernote doesn't send an email from the API request we manually send the user a link to activate the Shared Notebook.

Code to create LinkedNotebook: (From Shared User Account)

  var notebook = new Evernote.LinkedNotebook;
  notebook.shareName = options.shareName;
  notebook.username = options.username;
  notebook.shardId = options.shardId;
  notebook.shareKey = options.shareKey;

  var userclient = new Evernote.Client({token: token, sandbox: sandbox});
  var notestore = userclient.getNoteStore();
  notestore.createLinkedNotebook(userclient.token, notebook, function(err, results){
      callback(err, results);
  });

And the example response:

{ 
 shareName: 'Notebook Name',
 username: '...',
 shardId: 'sxxx',
 shareKey: 'xxxx-sxxx',
 uri: null,
 guid: '4f8df3c2-...',
 updateSequenceNum: 630,
 noteStoreUrl: 'https://www.evernote.com/shard/sxxx/notestore',
 webApiUrlPrefix: 'https://www.evernote.com/shard/sxxx/',
 stack: null,
 businessId: null
}

Has anyone had any luck creating a Linked Notebook from the API? It seems like the createLinkedNotebook API call is not working correctly. Thanks for your help.

Upvotes: 1

Views: 458

Answers (1)

akhaku
akhaku

Reputation: 1157

tl;dr you can't do what you're trying to do right now, sorry.

So there are a couple pieces missing here, not something you can do much about.

The first piece is that the shared notebook must be "claimed" by a user (the recipient), during which it gets assigned to the user. Until it's claimed, a LinkedNotebook pointing to the SharedNotebook won't actually give you access to the underlying Notebook - authenticateToSharedNotebook will fail.

The second piece is the shareKey itself. We renamed the struct member you see as shareKey to globalId on the SharedNotebook and sharedNotebookGlobalId on the LinkedNotebook - we're currently in the process of updating our developer documentation, and then we'll update the sdks. To "claim" a sharedNotebook, the recipient needs to call authenticateToSharedNotebook with the shareKey, not the globalId. The catch is that we don't expose a method to generate the real shareKey, so there's no way for third-party clients to generate this and join the shared notebook. Once it is claimed, you can call authenticateToSharedNotebook with the globalId to get access to the notebook.

There's a shareNotebook method we added that send an email as part of the API call. That email contains a link for the user to click on which contains the shareKey and allows claiming a SharedNotebook, but that isn't currently in the SDKs or documented. We'll hopefully get it up with this round of doc updates.

Upvotes: 2

Related Questions