Sharing (and Un-Sharing) Notes

How to start and stop sharing a single note, as well as how to retrieve a list all of the shared notes in an Evernote account.

  • Single Note Sharing

    Single notes can be shared in one of two ways: publicly (using a public note URL) or via email. The latter isn’t exactly sharing as much as it is emailing a copy of a note, so we’re going to focus on the former: sharing via a public shared URL. Note that there isn’t a way to share a single note with only one other person; anybody who knows the URL for a shared note will be able to view it.

    In order to share a single note, you’ll need the following information:

    • The GUID of the note you’d like to share.
    • The ID of the Shard that houses the note to be shared.
    • A valid authentication token or developer token.
    • Initialized instances of NoteStore.Client and UserStore.Client

    The Shard ID can be determined at runtime by querying the UserStore:

    Assuming all of that is in place, sharing a note is actually quite simple. By calling NoteStore.shareNote and passing a valid authentication token and the GUID of the note you’d like to share. In return, you’ll get a Share Key from the Evernote Cloud API that can be used in conjunction with the note GUID to view a read-only version of the note.

    Here’s a snippet of code that illustrates how the whole process works:

    Assuming nothing broke, the above function will return a public note URL that looks something like this:

    https://www.evernote.com/shard/s1/sh/36dd7123-12c0-457a-a6d0-75555fcc7770/3afc29de3493d0d333b54cf1822be92c

    The last two pieces of data in the URL are the note GUID and the share key.

  • Stop Sharing a Note

    This is about as close to a one-liner as you can get.

    You’ll need an initialized NoteStore.Client instance, a good authentication token and the GUID of the note in question. With those things in place, it’s as simple as calling NoteStore.stopSharingNote:

  • Listing All Shared Notes in an Account

    To search for all of the shared notes in a user’s account, we need to create a NoteFilter object and set its words member to sharedate:* (indicating that the note is shared and we don’t care when). Here’s a function that retrieves all of the shared notes in a user’s account (up to an arbitrary maximum of 500 notes):

    After creating and populating our NoteFilter instance, we repeatedly call NoteStore.findNotes, asking for 50 notes each time, collecting the responses into a sharedNotes collection. Once we hit our maximum number of notes or our sharedNotes collection is no longer evenly divisible by 50 (indicating that we received less than 50 notes during the most recent call to NoteStore.findNotes), we return sharedNotes.

Stay on top of what's happening in the Evernote developer community.