Luis valencia introduction to share point webhooks
-
Upload
luis-valencia-microsoft-mvp -
Category
Software
-
view
40 -
download
1
Transcript of Luis valencia introduction to share point webhooks
Introduction to SharePoint WebHooksLuis [email protected]
Code samplesGuidance documentationMonthly community callsCase Studies
SharePoint FrameworkSharePoint add-insMicrosoft Graph Office 365 APIs
Sharing is caring…
http://aka.ms/SharePointPnP
• 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?
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!
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!
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
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
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
SharePoint list WebHooks in action!
Demo
• 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
• 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
• 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