Evernote doesn’t like you using the search functionality in the API to look for changes that occur to a note. Instead you are encouraged to get notification of changes using webhooks. This works by receiving an HTTP post from Evernote every time that a note is created or updated and by reading the payload associated with that webhook you can get some basic information on it.
What does the Webhook look like?
The very first thing to know about Evernote webhooks is that in order to receive them you need to have registered for an API key and also registered to receive webhooks. Additionally, you cannot ask for a blank “I’d like webhooks for absolutely everything please” instead you need to nominate an notebook to watch and just get webhooks for changes there.
Here’s an example of a typical webhook:
/webhook?userId=123456&guid=12f34567-0012-1e2e-1234-567efdd8901e&notebookGuid=12345678-9d01-2c342-a56a-fd789e0dc123&reason=update
The payload consists of the following:
- userId – of the account that the note is associated with
- guid – the unique reference of the note
- notebookGuid – the unique reference of the notebook that the note is in
- reason, which can be one of the following:
- notebook_create
- notebook_update
- create (new note)
- update (existing note)
- business_notebook_create
- business_notebook_update
- business_create
- business_update
Obviously, for some of the reasons shown above, such as notebook_create, the guid field won’t be available as it isn’t relevant.
Using the following snippet of PHP we can check the webhook is for us and separate out the relevant parts.
// does this have the required payload and is it for us?
if (empty($_REQUEST) || (!empty(USER) && $_REQUEST['userId'] != USER)) die;
// get the reason we are being polled
$reason = $_REQUEST['reason'];
// get the details
$userId = $_REQUEST['userId'];
$noteGuid = $_REQUEST['guid'];
$notebookGuid = $_REQUEST['notebookGuid'];
Armed with the above you can now call the API to get more information about the note that has been created or updated:
// Initialize Evernote client
$client = new \Evernote\Client(OAUTH, FALSE);
$noteStore = $client->getAdvancedClient()->getNoteStore();
// Retrieve note details
$note = $client->getNote($noteGuid);
$title = $note->title;
echo $title;
Checking the details in Evernote
It is possible to check the note that has triggered the webhook in Evernote itself, but only in the webclient. You can do this using the following url format:
https://www.evernote.com/client/web#/notebook/<note book guid>/note/<note guid>
So, using the webhook example above this would look like this:
https://www.evernote.com/client/web#/notebook/12345678-9d01-2c342-a56a-fd789e0dc123/note/12f34567-0012-1e2e-1234-567efdd8901e
Using the above it should be possible to efficiently receive updates from Evernote that you can then go on to process.