SharePoint Pals
 | Sign In
As a SharePoint developer, what you should know about Web-Hooks ?
by Sriram Varadarajan 2 Dec 2016
Author
Enterprise Architect
Visits   
Today  :   24     Total  :    383

This article on Web hooks for SharePoint developers is a compilation of basic what and why questions related to web hooks.

What is Web Hooks?

In a simple term it’s the way of notification (Push model instead of Pull)

Does Web Hooks belong to MS/SharePoint?

No, Web Hooks is a universal model of notification and MS is just consuming the same.

When to go for Web Hooks?

It’s supports Async event (means ‘ed event) but if you need Synchronous event (‘ing) continue to use remote event receiver.

Are web hooks available in SharePoint online?

Not yet, but it’s available for Outlook and OneDrive

How Web hooks works?

As mentioned earlier it’s a notification service and for us to consume the service we need to do the following:

1. Our application needs to tell SharePoint that you want to have a web hook on particular object (MS à The first version of Web hook will be available for SP List)

2. First step should be Subscribe for a webhook using a REST POST call

        1. [Your application -> SharePoint] POST /_api/web/lists('list-id')/subscriptions
        2. The content type should contain the following:

"resource", (sharepoint URL)

"notificationUrl" and (our Application)

"expirationDateTime"

Example:

 Content-Type: application/json 
 {
     "resource": "https://contoso.sharepoint.com/_api/web/lists({id})",
     "notificationUrl": "https://{your host}/your/webhook/service ",
     "expirationDateTime": "2016-06-27T16:17:57+00:00"
 }

Note : As of now, the expirationPeriod can be of MAX 6 months (Remote Event Receiver doesn't have this limit)

3. SharePoint Sends a validation token back POST https://{your host}/your/webhook/service?validationToken={randomString}

4. Your web hook notification service end point should Reply 200 OK to Sharepoint along with the randomstring and this should take place with in 5 sec

5. [SharePoint to Your application] Acknowledged by SharePoint

With

1. Response 201 created

2. "id", "expirationDateTime", "notificationUrl" and "resource" sent back as response

3. "id" will be the subscription id

Example:

 Content-Type: application/json
 {
     "id": "a8e6d5e6-9f7f-497a-b97f-8ffe8f559dc7",
     "expirationDateTime": "2016-04-27T16:17:57Z",
     "notificationUrl": " https://{your host}/your/webhook/service ",
     "resource": "{id}"
 }

What happens when a change happens in a SharePoint?

SharePoint Notifies the change to our application like;

POST https://{your host}/your/webhook/service

And our application should return 200 with in 5 seconds

Sample response from SharePoint

 {
     "value": [
         {
             "subscriptionId": "91779246-afe9-4525-b122-6c199ae89211",
             "clientState": "00000000-0000-0000-0000-000000000000",
             "expirationDateTime": "2016-04-30T17:27:00.0000000Z",
             "resource": "b9f6f714-9df8-470b-b22e-653855e1c181", // (LISTID)
             "tenantId": "00000000-0000-0000-0000-000000000000",
             "siteUrl": "/",
             "webId": "dbc5a806-e4d4-46e5-951c-6344d70b62fa"
         }
     ]
 }

Note:

How to consume a WebHooks is beyond the scope of this blog (as it’s very complicated now), we might have to wait for the next release but the core should still remain the same.

blog comments powered by Disqus

SharePoint Pals

Pals
SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile

Training

Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community




SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to articles@sharepointpals.com in a word document.

Related Resources

Recent Tweets

Twitter November 21, 21:08
Implementing Multi-Threading with MaxDegreeOfParallelism in SharePoint using CSOM – An Insight - https://t.co/RNM7eVuyaa

Twitter November 21, 12:48
Configure Windows Firewall for SQL Server Analysis Service (SSAS) - https://t.co/re2H0cnGwn

Twitter November 21, 12:46
Implementing Multi-Threading in SharePoint To Upload Files using CSOM C# – An Insight - https://t.co/18QwUQG2eR

Twitter November 20, 21:48
How to Get the Client Context Using App Access token, by passing Client ID using CSOM in SharePoint Office 365 - https://t.co/wpmlJfTeWx

Twitter November 18, 21:30
How to Enable Auto Approval For Permission Requests in Community Site Template – Office 2013 using Client Side Object Model (CSOM) C#

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation