Query SharePoint Online Calendar using the REST API

Pulling your hair out trying to query a SharePoint Calendar using the REST API? Fret no longer! I’ve done the stressing for you!
Recently a project had a requirement to display all events that occur today, including recurring events.

Partial credit to http://georgetowndctechie.blogspot.com.au/2013/08/sharepoint-caml-query-to-get-todays.html for providing the base CAML to mostly achieve what we were after.

It was a great start, but any events that started Today but before the time of making the request would not be returned in the dataset. How annoying! Oh well, just another SharePoint quirk.
Some small modifications to the CAML to account for this case and we were in business!

During development I encountered a mysterious REST API error on the GetItems endpoint when POSTing to it. The error message was:

"error":{
   "code":"-2130575251, Microsoft.SharePoint.SPException",
   "message":{
        "lang":"en-US",
        "value":"The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again."
    }
}

After a thorough head scratching session I ended up finding a workaround here http://stackoverflow.com/a/32440351. A new form digest value needed to be requested. More SharePoint quirks.

And finally, the code!

Let me know if this helped you!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.