My main goal is a very simple duplicate of alerts, to play around with webhooks, just a simple
"User X changed field Title from 'Hello' to 'World'".
So far so good
After some struggle I finally managed to set up webhhoks (SharePoint List Subscription) to my Azure Functions using App Only Token (Azure AD) with adal-node and a function called acquireTokenWithClientCertificate
.
Even though it was hard for me to figure out, the app only authentication seems very handy to have, and it seems the token will never expire.
The Subscription on the other hand will expire after a set date, but this date can't be older than 6 months, so I actually need a scheduled Azure Function just to re-new that subscription.
I run this on a weekly basis, I'm not going to expect some code in 6 months to "just work".
But then...
What I haven't been able to solve is actually fetching the item and knowing what has changed.
Surprisingly the webhook doesn't contain any interesting information. I can set some static querystring, but beside that I won't even get the item ID, all I get is "something changed". The webhook MSDN says "Your application is expected to use the GetChanges API...".
So I have been playing around with the GetChanges API. To me it looks like a wrapper for the good ol' /_vti_bin/Lists.asmx, so much of a wrapper it actually returns XML (which I just parse with xml2js).
What I have so far
Anyway, I initially use GetChanges
to get the newest ChangeToken, then on the next change I use that to get changes for GetListItemChangesSinceToken
and this will actually give me the item with ows_FieldValue
layout, which is the item in total plain text. But what should I compare this against? If I fetch the item using REST it will be the same updated item, I can't see the changes. It's also difficult to compare ows_SomeLookup
against normal /item(${id})
without some logic.
I've been playing around some with GetListItemSinceLastToken
as I can pass in a query, such as item ID. This works, but again I only get last change. I also pass in ViewFields
since I have more than 8 lookup columns, so not setting it would fail.
So: How on an item change am I suppose to know what item fields have actually changed, and to what?
Update 2017-07-13
I have been looking at the new Graph API for SharePoint, and in theory I should be able to get items from there, and then run a deltaLink
-query.
Except there are two problems:
- The
deltaLink
doesn't actually show in results, only@odata.nextLink
, so I suspect this api just a wrapper around the SharePoint REST API, so nodeltaLink
-query will be available. - I'm not able to get any
values
when calling Graph API with Azure AD token (had to create new token, added all Graph API permissions), only via the Graph explorer. I get the list, but not/items
.
Note that this API just still just beta.
Update 2018-01-31
A discussion on Gitter, plus this commit draw the attention of an (at writing moment) undocumented feature; /versions
.
It is now, amazingly, possible to get item versions using the REST API, solving this question, albeit not using GetChanges.
Note that this is only available on SharePoint Online, not on-premise.