As a SharePoint developer, what you should know about Web-Hooks ?


Sriram Varadarajan
Enterprise Architect
Published On :   02 Dec 2016
Visit Count
Today :  1    Total :   2394
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial


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.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

KWizCom Forms App