Luis valencia introduction to share point webhooks

12
Introduction to SharePoint WebHooks Luis Valencia @levalencia Luisevalencia.com

Transcript of Luis valencia introduction to share point webhooks

Page 1: Luis valencia  introduction to share point webhooks

Introduction to SharePoint WebHooksLuis [email protected]

Page 2: Luis valencia  introduction to share point webhooks

Code samplesGuidance documentationMonthly community callsCase Studies

SharePoint FrameworkSharePoint add-insMicrosoft Graph Office 365 APIs

Sharing is caring…

http://aka.ms/SharePointPnP

Page 3: Luis valencia  introduction to share point webhooks

• A WebHook is “a way to be notified of a done change” push model instead of a pull model• No synchronous (“-ing”) event support, keep on using RER’s

for that• Universal model used not just by Office 365

(e.g. WordPress, GitHub, MailChimp,…)• Released to production for SharePoint Online Lists in January 2017

What are WebHooks?

Page 4: Luis valencia  introduction to share point webhooks

Subscribe to a WebHook

HTTP/1.1 200 OKContent-Type: text/plain{randomString}

SharePoint Service

POST /_api/web/lists('list-id')/subscriptionsYour application

POST https://{your host}/your/webhook/service ?validationtoken={randomString}

Your WebHook notification

service endpoint

HTTP/1.1 201 CreatedYour application

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" }

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}“ }

Maximum 6 months

expiration period!

Respond in < 5 seconds!

Page 5: Luis valencia  introduction to share point webhooks

Event notification in action

HTTP/1.1 200 OK

SharePoint Service

Your WebHook notification

service endpoint

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

{ "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", "tenantId":"00000000-0000-0000-0000-000000000000", "siteUrl":"/", "webId":"dbc5a806-e4d4-46e5-951c-6344d70b62fa" } ]}

Respond in < 5 seconds!

Page 6: Luis valencia  introduction to share point webhooks

Processing a notification event

Your WebHook notification

service endpoint

SharePoint ServicePOST https://{your host}/your/webhook/service

Storage Queue

WebJob

GetChanges() CSOM API

Process the changes

HTTP/1.1 200 OK

Page 7: Luis valencia  introduction to share point webhooks

GetChanges() patternSharePoint Service

WebHook creation: POST /_api/web/lists('list-id')/subscriptions

Your applicationGrab “CurrentChangeToken” from list

Your WebHook notification

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

Storage Queue

WebJobGetChanges() C

SOM

API

Grab change token from DB

Persis last used token per subscription

SQL Azure DBPersis token

per subscription

Page 8: Luis valencia  introduction to share point webhooks

Webhooks versus Azure FunctionsAutomatic

hosting and scaling

Use C#, JavaScript,…for your notification service

Embedded test console

Function times out in 5 minutes for free version, but respects “Always

On” in paid versions

Possible webhook pattern: function

receives notification and

adds it to a queue, function B is

triggered by the queue message and processes it

Page 9: Luis valencia  introduction to share point webhooks

SharePoint list WebHooks in action!

Demo

Page 10: Luis valencia  introduction to share point webhooks

• WebHooks have a retry mechanism with an incremental back off strategy

• WebHook calls are less taxing for your service endpoint:• The WebHook payload is very small• Notifications are batched because processing depends on the CSOM GetChanges() call

• WebHooks are more secure as no event information is passed along during the notification

• WebHooks are easier to consume by “non-SharePoint” developers

• No WCF based endpoints, regular HTTP services are sufficient (e.g. Web API / Azure Function)

Why use Webhooks over RER’s

Page 11: Luis valencia  introduction to share point webhooks

• Connect remote debugger to your service and web job running in Azure

• Use the Azure Functions development environment to call your notification service there will be VS support soon

• Use ngrok (https://ngrok.com/) are alternative to create a tunnel to your service running on localhost

Debugging your notification service

Page 12: Luis valencia  introduction to share point webhooks

• What are WebHooks• http://culttt.com/2014/01/22/webhooks/

• SharePoint WebHooks• https://github.com/SharePoint/sp-dev-samples/tree/master/Samples/WebHooks.List.AzureAD• https://dev.office.com/sharepoint/docs/apis/webhooks/overview-sharepoint-webhooks• https://dev.office.com/sharepoint/docs/apis/webhooks/webhooks-reference-implementation • https://dev.office.com/sharepoint/docs/apis/webhooks/sharepoint-webhooks-using-azure-functio

ns

• WebHooks in OneDrive• https://dev.onedrive.com/webhooks/create-subscription.htm• https://github.com/OneDrive/onedrive-webhooks-aspnet

• WebHooks in Outlook• https://msdn.microsoft.com/office/office365/APi/notify-rest-operations• https://github.com/OfficeDev/PnP/tree/dev/Samples/OutlookNotificationsAPI.WebAPI

Resources