SlideShare une entreprise Scribd logo
1  sur  42
Getting notified by SharePoint with
the webHook functionality
Elio Struyf – Trainer @ U2U – MVP
#SPSNL17 - @eliostruyf
What are WebHooks?
#SPSNL17 - @eliostruyf
What are WebHooks?
• Event driven notifications AKA callbacks from the web
• Universal model used by many services: GitHub, Slack, MailChimp, …
• Pushing mechanism  asynchronous!
• Implemented in various Office 365 Services
• Microsoft Graph
• Connectors
• SharePoint
#SPSNL17 - @eliostruyf
WebHooks in SPO went GA
in January 2017
#SPSNL17 - @eliostruyf
Where can you use them?
• SharePoint
• List
• Libraries
• Microsoft Graph
• Messages, events, contacts, conversations in groups, OneDrive root items
#SPSNL17 - @eliostruyf
The good and the bad
• WebHooks are asynchronous mechanism
• Retry mechanism
• 5 times with a delay of 5 minutes
• More secure, no event information is passed
• No support for event-ing events  only RER can be used
• Add-ing, update-ing, delete-ing
• Requires some setup, but once done, it is easy to maintain
#SPSNL17 - @eliostruyf
Remote event receivers vs WebHooks
Remote event receivers
• Synchronous (-ing) and/or async (-ed)
• One request
• One change = one request
• Changes are inside the request body
• 2 minutes to respond
• Indefinitely
• One try
WebHooks
• Async only
• Retry logic: 5 times
• Batched requests
• Only notification  more secure
• 5 seconds to respond
• Needs subscription renewal
• When it fails, you can try again later
Both use the same base principle: call an external URI when something happens
#SPSNL17 - @eliostruyf
How to start using
WebHooks?
#SPSNL17 - @eliostruyf
By subscribing to a WebHook!
Notification service
1. Create a subscription
4. SharePoint responds with subscription info
#SPSNL17 - @eliostruyf
Important things about subscribing
Subscribing: POST - /_api/web/lists/getbytitle('Title')/subscriptions
{
"resource": "https://tenant.sharepoint.com/sites/site/_api/web/lists/getbytitle('Title')",
"notificationUrl": "Your notification service URL – HTTPS is required",
"expirationDateTime": "Date value - maximum 6 months",
"clientState": "String value for validation (optional)"
}
#SPSNL17 - @eliostruyf
Important things about subscribing
SharePoint calls your notification service:
POST - https://notification-service?validationToken={random-guid}
Respond with:
Important: notification service needs to respond in < 5 seconds
Status: 200
Body: validationtoken
#SPSNL17 - @eliostruyf
Important things about subscribing
When validation is done, SharePoint returns the subscription
information
#SPSNL17 - @eliostruyf
Local development and testing:
ngrok - Secure tunnels to localhost
https://ngrok.com/
#SPSNL17 - @eliostruyf
Demo
Subscribing to a WebHook
#SPSNL17 - @eliostruyf
More about the notification
service
#SPSNL17 - @eliostruyf
Notification service details
• You choose the technology: Web API, Node.js, …
• Respond in < 5 seconds and with status: 200-299 range
• Retry mechanism  5 times (5 minute in between)
• Not for the validation process
• Receives minimal information, just a message “something” happened
• Service has to gather the changes from SharePoint
#SPSNL17 - @eliostruyf
Minimal notification information?
#SPSNL17 - @eliostruyf
This is what you will receive
{
"value": [
{
"subscriptionId":"2e7f9cd7-5cdb-4d57-b4d5-edc083202378",
"clientState":null,
"expirationDateTime":"2017-08-16T10:38:54.3440000Z",
"resource":"465b36fc-e778-4047-8425-3f906497dfc3",
"tenantId":"9fee8694-d491-4e3e-b10b-a81ee76dfad9",
"siteUrl":"/sites/Webhooks",
"webId":"e363e4e9-0161-495f-a652-15c618e2e963“
}]
}
#SPSNL17 - @eliostruyf
How do I know what happened?
• SPList.GetChanges method
• POST - `/_api/web/lists(guid'${resource}')/getchanges`
• Specify a change query + change token
{
"Item": true,
"Add": true,
"Update": true,
"DeleteObject": true,
"Restore": true,
"ChangeTokenStart": {
"StringValue": "1;3;465b36fc-e778-4047-8425-3f906497dfc3;636307008298500000;60877869"
}
}
ChangeQuery properties: http://elst.es/2rib2q7
#SPSNL17 - @eliostruyf
Anatomy of the change token
1;3;465b36fc-e778-4047-8425-3f906497dfc3;636307008298500000;60877869
Version information (currently always 1)
Scope of the change. 3 = List & library changes.
Resource ID, can be retrieved from the subscription notification
Timestamp in ticks
Change number
in the event
cache table. You
can start with -1.
#SPSNL17 - @eliostruyf
Using the change token
• Using GetChanges without ChangeToken would return everything
• By specifying a change token, you control what you need
#SPSNL17 - @eliostruyf
Things to know about the change token
• First time, create it yourself (ex.: get all changes of the last hour)
• Per GetChanges request, you get the latest change token
• Store the latest change token, use it for the next call
{
"ChangeToken": {
"StringValue":"1;3;465b36fc-e778-4047-8425-3f906497dfc3;636307074435230000;60879219"
},
"ChangeType": 2,
"SiteId": "1432d309-9f6a-4dae-8d35-532dec332b86",
"ItemId": 3,
…
}
#SPSNL17 - @eliostruyf
GetChanges response value
• Notice the ChangeType, it is an enumeration
• 1 = added, 2 = updated, 3 = deleted
{
"ChangeToken": {
"StringValue":"1;3;465b36fc-e778-4047-8425-3f906497dfc3;636307074435230000;60879219"
},
"ChangeType": 2,
"SiteId": "1432d309-9f6a-4dae-8d35-532dec332b86",
"ItemId": 3,
"ServerRelativeUrl":"",
…
"WebId":"e363e4e9-0161-495f-a652-15c618e2e963"
}
More information about the ChangeTypes - http://elst.es/2ruAfKn
#SPSNL17 - @eliostruyf
Supported event types
• Added
• Updated
• Deleted
• CheckedOut
• CheckedIn
• UncheckedOut
• AttachmentAdded
• AttachmentDeleted
• FileMoved
• VersionDeleted
• FileConverted
#SPSNL17 - @eliostruyf
Creating your notification
service
#SPSNL17 - @eliostruyf
Tokens, all about the OAuth tokens
• Azure AD app registration
• Generate a certificate
• SharePoint requires access tokens with appidacr property set to 2
• Application Authentication Context Class Reference
• 0 = Public client
• 1 = Identified by a client id and secret
• 2 = Identified by a certificate
Azure AD application manifest
Store this in a separate file (privatekey.pem)
Fingerprint is also require to get the access token
#SPSNL17 - @eliostruyf
public getAppOnlyAccessToken(config: IConfig): Promise<any> {
return new Promise((resolve, reject) => {
const certificate = fs.readFileSync(path.join(__dirname, 'privatekey.pem'), { encoding : 'utf8'});
const authContext = new adal.AuthenticationContext(config.adalConfig.authority);
authContext.acquireTokenWithClientCertificate(config.adalConfig.resource, config.adalConfig.clientID, certificate,
config.adalConfig.fingerPrint, (err, tokenRes) => {
if (err) {
reject(err);
}
const accesstoken = tokenRes.accessToken;
resolve(accesstoken);
});
});
}
Get an access token via a certificate and
private key with ADAL for JS
#SPSNL17 - @eliostruyf
Important APIs
• Retrieve all list / library subscriptions
GET - /_api/web/lists/getbytitle('ListTitle')/subscriptions
• Update a subscription
PATCH - /_api/web/lists/getbytitle('ListTitle')/subscriptions('${subId}')
Body: { "expirationDateTime": "New expiration date" }
• Delete a subscription
DELETE - /_api/web/lists/getbytitle('ListTitle')/subscriptions('${subId}')
#SPSNL17 - @eliostruyf
Demo
Sample application
#SPSNL17 - @eliostruyf
A real life setup and configuration
SPO config page
HTTP Triggered function
Queue triggered function
1. Subscribe 2. Validate
3. Trigger change
4. Notify service
5. Put notification message on a queue6. Respond with 200
Use the page to:
- Check subscriptions
- Update subscriptions
- Delete subscriptions
7. Trigger another Azure function that will do change handling
8. Retrieve latest change token10. Store latest change token
#SPSNL17 - @eliostruyf
Demo
SPFx + Azure Functions
#SPSNL17 - @eliostruyf
Recap
• Notification service has to respond in < 5 seconds
• Retry mechanism  5 times (5 minute delay)
• Not for the validation process
• Subscription expiration date: 6 months
• Create a check or renewal process in your subscription processor
• You need to ask for the changes that happened  minimal
information is send
• Get the changes only what you are interested in
• No synchronous events for SPO  event-ing events
Questions?
Office Servers & Services MVP
Azure / Office 365 / SharePoint
@eliostruyf
www.eliostruyf.com
info@estruyf.be
Elio Struyf
Lead trainer and architect
#SPSNL17 - @eliostruyf
Resources
Certificate creation process with makecert - http://elst.es/2rhveZc
Keycred GitHub - http://elst.es/2pW77vm
All about the Change token - http://elst.es/2runG1M
ChangeType enumeration - http://elst.es/2ruAfKn
ChangeQuery properties - http://elst.es/2rib2q7
C# Sample application - http://elst.es/2qUYg0M
Node.js / TypeScript sample application - http://elst.es/2qVpTqT or http://elst.es/2cycM82
SharePoint List WebHooks docs - http://elst.es/2qwl1as - http://elst.es/2quVjD0
SPSNL17 - Getting notified by SharePoint with the webhook functionality - Elio Struyf

Contenu connexe

Tendances

O365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
O365Engage17 - How to Automate SharePoint Provisioning with PNP FrameworkO365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
O365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
NCCOMMS
 
O365Engage17 - Managing share point online end to-end with powershell
O365Engage17 - Managing share point online end to-end with powershellO365Engage17 - Managing share point online end to-end with powershell
O365Engage17 - Managing share point online end to-end with powershell
NCCOMMS
 
Yo Office! Use your SPFx Skills to Build Add-Ins for Word, Excel, Outlook and...
Yo Office! Use your SPFx Skills to Build Add-Ins for Word, Excel, Outlook and...Yo Office! Use your SPFx Skills to Build Add-Ins for Word, Excel, Outlook and...
Yo Office! Use your SPFx Skills to Build Add-Ins for Word, Excel, Outlook and...
BIWUG
 

Tendances (20)

O365Engage17 - Hybrid flow and power apps
O365Engage17 - Hybrid flow and power appsO365Engage17 - Hybrid flow and power apps
O365Engage17 - Hybrid flow and power apps
 
I5 - Bring yourself up to speed with power shell
I5 -  Bring yourself up to speed with power shellI5 -  Bring yourself up to speed with power shell
I5 - Bring yourself up to speed with power shell
 
O365Engage17 - Configuring share point hybrid search
O365Engage17 - Configuring share point hybrid searchO365Engage17 - Configuring share point hybrid search
O365Engage17 - Configuring share point hybrid search
 
O365Engage17 - Identity in the cloud foundation for o365
O365Engage17 - Identity in the cloud foundation for o365O365Engage17 - Identity in the cloud foundation for o365
O365Engage17 - Identity in the cloud foundation for o365
 
Ensuring Successful Office 365 Tenant to Tenant Migration SPS Cambridge 2017...
Ensuring Successful Office 365 Tenant to Tenant Migration  SPS Cambridge 2017...Ensuring Successful Office 365 Tenant to Tenant Migration  SPS Cambridge 2017...
Ensuring Successful Office 365 Tenant to Tenant Migration SPS Cambridge 2017...
 
Architecture Evolution 2018
Architecture Evolution 2018Architecture Evolution 2018
Architecture Evolution 2018
 
O365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
O365Engage17 - How to Automate SharePoint Provisioning with PNP FrameworkO365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
O365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
 
Connecticut Salesforce Developer Group - Jan 2017
Connecticut Salesforce Developer Group - Jan 2017Connecticut Salesforce Developer Group - Jan 2017
Connecticut Salesforce Developer Group - Jan 2017
 
O365Engage17 - Ins and outs of monitoring office 365
O365Engage17 - Ins and outs of monitoring office 365O365Engage17 - Ins and outs of monitoring office 365
O365Engage17 - Ins and outs of monitoring office 365
 
O365Engage17 - Managing share point online end to-end with powershell
O365Engage17 - Managing share point online end to-end with powershellO365Engage17 - Managing share point online end to-end with powershell
O365Engage17 - Managing share point online end to-end with powershell
 
Getting notified by SharePoint with the webhook functionality
Getting notified by SharePoint with the webhook functionalityGetting notified by SharePoint with the webhook functionality
Getting notified by SharePoint with the webhook functionality
 
Logic Apps – Deployments
Logic Apps – DeploymentsLogic Apps – Deployments
Logic Apps – Deployments
 
Create Salesforce online IDE in 30 minutes
Create Salesforce online IDE in 30 minutesCreate Salesforce online IDE in 30 minutes
Create Salesforce online IDE in 30 minutes
 
Reporting in Office 365 - ATL SharePoint and Office 365 User Group
Reporting in Office 365 - ATL SharePoint and Office 365 User GroupReporting in Office 365 - ATL SharePoint and Office 365 User Group
Reporting in Office 365 - ATL SharePoint and Office 365 User Group
 
O365Engage17 - Microsoft stream the future of video
O365Engage17 - Microsoft stream   the future of videoO365Engage17 - Microsoft stream   the future of video
O365Engage17 - Microsoft stream the future of video
 
Collab365 Global Summit Slides
Collab365 Global Summit SlidesCollab365 Global Summit Slides
Collab365 Global Summit Slides
 
SPUnite17 Getting Notified by SharePoint with WebHooks
SPUnite17 Getting Notified by SharePoint with WebHooksSPUnite17 Getting Notified by SharePoint with WebHooks
SPUnite17 Getting Notified by SharePoint with WebHooks
 
Yo Office! Use your SPFx Skills to Build Add-Ins for Word, Excel, Outlook and...
Yo Office! Use your SPFx Skills to Build Add-Ins for Word, Excel, Outlook and...Yo Office! Use your SPFx Skills to Build Add-Ins for Word, Excel, Outlook and...
Yo Office! Use your SPFx Skills to Build Add-Ins for Word, Excel, Outlook and...
 
O365Engage17 - New dawn of share point apps
O365Engage17 - New dawn of share point appsO365Engage17 - New dawn of share point apps
O365Engage17 - New dawn of share point apps
 
Workflows in SharePoint 2013
Workflows in SharePoint 2013Workflows in SharePoint 2013
Workflows in SharePoint 2013
 

Similaire à SPSNL17 - Getting notified by SharePoint with the webhook functionality - Elio Struyf

Entwickler camp2012 how to connect your app to the activity stream with x_pages
Entwickler camp2012 how to connect your app to the activity stream with x_pagesEntwickler camp2012 how to connect your app to the activity stream with x_pages
Entwickler camp2012 how to connect your app to the activity stream with x_pages
Frank van der Linden
 
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
Kiril Iliev
 

Similaire à SPSNL17 - Getting notified by SharePoint with the webhook functionality - Elio Struyf (20)

PnP Monthly Community Call - April 2018
PnP Monthly Community Call - April 2018PnP Monthly Community Call - April 2018
PnP Monthly Community Call - April 2018
 
SharePoint 2013 REST APIs
SharePoint 2013 REST APIsSharePoint 2013 REST APIs
SharePoint 2013 REST APIs
 
Entwickler camp2012 how to connect your app to the activity stream with x_pages
Entwickler camp2012 how to connect your app to the activity stream with x_pagesEntwickler camp2012 how to connect your app to the activity stream with x_pages
Entwickler camp2012 how to connect your app to the activity stream with x_pages
 
Foxtrot: Real time analytics
Foxtrot: Real time analyticsFoxtrot: Real time analytics
Foxtrot: Real time analytics
 
10 points to make a rogue SharePoint environment really, really secure..
10 points to make a rogue SharePoint environment really, really secure..10 points to make a rogue SharePoint environment really, really secure..
10 points to make a rogue SharePoint environment really, really secure..
 
Microservices and the Art of Taming the Dependency Hell Monster
Microservices and the Art of Taming the Dependency Hell MonsterMicroservices and the Art of Taming the Dependency Hell Monster
Microservices and the Art of Taming the Dependency Hell Monster
 
The Spring Update
The Spring UpdateThe Spring Update
The Spring Update
 
Ajug - The Spring Update
Ajug - The Spring UpdateAjug - The Spring Update
Ajug - The Spring Update
 
PnP Monthly Community Call - December 2017
PnP Monthly Community Call - December 2017PnP Monthly Community Call - December 2017
PnP Monthly Community Call - December 2017
 
Develop IoT project with AirVantage M2M Cloud
Develop IoT project with AirVantage M2M CloudDevelop IoT project with AirVantage M2M Cloud
Develop IoT project with AirVantage M2M Cloud
 
Spring MVC to iOS and the REST
Spring MVC to iOS and the RESTSpring MVC to iOS and the REST
Spring MVC to iOS and the REST
 
How Carolinas HealthCare System Governs SharePoint
How Carolinas HealthCare System Governs SharePointHow Carolinas HealthCare System Governs SharePoint
How Carolinas HealthCare System Governs SharePoint
 
Webinar: Troubleshooting Connections PINK
Webinar: Troubleshooting Connections PINKWebinar: Troubleshooting Connections PINK
Webinar: Troubleshooting Connections PINK
 
slides
slidesslides
slides
 
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
jsSaturday - PhoneGap and jQuery Mobile for SharePoint 2013
 
Introduction to PowerShell for SharePoint Admins and Developers
Introduction to PowerShell for SharePoint Admins and DevelopersIntroduction to PowerShell for SharePoint Admins and Developers
Introduction to PowerShell for SharePoint Admins and Developers
 
Externalizing Authorization in Micro Services world
Externalizing Authorization in Micro Services worldExternalizing Authorization in Micro Services world
Externalizing Authorization in Micro Services world
 
Evolution of the REST API
Evolution of the REST APIEvolution of the REST API
Evolution of the REST API
 
How bol.com makes sense of its logs, using the Elastic technology stack.
How bol.com makes sense of its logs, using the Elastic technology stack.How bol.com makes sense of its logs, using the Elastic technology stack.
How bol.com makes sense of its logs, using the Elastic technology stack.
 
Olist Architecture v2.0
Olist Architecture v2.0Olist Architecture v2.0
Olist Architecture v2.0
 

Plus de DIWUG

Plus de DIWUG (12)

SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...
SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...
SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...
 
SPSNL17 - Secure Collaboration: Start classifying, labeling, and protecting y...
SPSNL17 - Secure Collaboration: Start classifying, labeling, and protecting y...SPSNL17 - Secure Collaboration: Start classifying, labeling, and protecting y...
SPSNL17 - Secure Collaboration: Start classifying, labeling, and protecting y...
 
SPSNL17 - Be more effective with the PnP Provisioning Engine - Erwin van Hunen
SPSNL17 - Be more effective with the PnP Provisioning Engine - Erwin van HunenSPSNL17 - Be more effective with the PnP Provisioning Engine - Erwin van Hunen
SPSNL17 - Be more effective with the PnP Provisioning Engine - Erwin van Hunen
 
SPSNL17 - Custom SharePoint integration for Dynamics365 - Martijn Eikelenboom
SPSNL17 - Custom SharePoint integration for Dynamics365 - Martijn EikelenboomSPSNL17 - Custom SharePoint integration for Dynamics365 - Martijn Eikelenboom
SPSNL17 - Custom SharePoint integration for Dynamics365 - Martijn Eikelenboom
 
SPSNL17 - Content publishing and communication strategies for Office 365 and ...
SPSNL17 - Content publishing and communication strategies for Office 365 and ...SPSNL17 - Content publishing and communication strategies for Office 365 and ...
SPSNL17 - Content publishing and communication strategies for Office 365 and ...
 
SPSNL17 - How to solve Azure AD Connect sync issues - Arjan Cornelissen
SPSNL17 - How to solve Azure AD Connect sync issues - Arjan CornelissenSPSNL17 - How to solve Azure AD Connect sync issues - Arjan Cornelissen
SPSNL17 - How to solve Azure AD Connect sync issues - Arjan Cornelissen
 
SPSNL17 - Introductie HoloLens - Augmented Reality in 2017 - Michiel Hamers
SPSNL17 - Introductie HoloLens - Augmented Reality in 2017 - Michiel HamersSPSNL17 - Introductie HoloLens - Augmented Reality in 2017 - Michiel Hamers
SPSNL17 - Introductie HoloLens - Augmented Reality in 2017 - Michiel Hamers
 
SPSNL17 - Adoption, I love it when a plan comes together - Katharina Schroeder
SPSNL17 - Adoption, I love it when a plan comes together - Katharina SchroederSPSNL17 - Adoption, I love it when a plan comes together - Katharina Schroeder
SPSNL17 - Adoption, I love it when a plan comes together - Katharina Schroeder
 
SPSNL17 - Delivering the promise of Software as a Service with Hybrid solutio...
SPSNL17 - Delivering the promise of Software as a Service with Hybrid solutio...SPSNL17 - Delivering the promise of Software as a Service with Hybrid solutio...
SPSNL17 - Delivering the promise of Software as a Service with Hybrid solutio...
 
SPSNL17 - Securing Office 365 and Microsoft Azure like a rock star (or groupi...
SPSNL17 - Securing Office 365 and Microsoft Azure like a rock star (or groupi...SPSNL17 - Securing Office 365 and Microsoft Azure like a rock star (or groupi...
SPSNL17 - Securing Office 365 and Microsoft Azure like a rock star (or groupi...
 
SPSNL17 - Deep-dive building SharePoint Framework solutions - Albert-Jan Scho...
SPSNL17 - Deep-dive building SharePoint Framework solutions - Albert-Jan Scho...SPSNL17 - Deep-dive building SharePoint Framework solutions - Albert-Jan Scho...
SPSNL17 - Deep-dive building SharePoint Framework solutions - Albert-Jan Scho...
 
SPSNL17 - The business & end-user guide into the new and modern SharePoint! -...
SPSNL17 - The business & end-user guide into the new and modern SharePoint! -...SPSNL17 - The business & end-user guide into the new and modern SharePoint! -...
SPSNL17 - The business & end-user guide into the new and modern SharePoint! -...
 

Dernier

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 

Dernier (20)

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

SPSNL17 - Getting notified by SharePoint with the webhook functionality - Elio Struyf

  • 1. Getting notified by SharePoint with the webHook functionality Elio Struyf – Trainer @ U2U – MVP
  • 2.
  • 4. #SPSNL17 - @eliostruyf What are WebHooks? • Event driven notifications AKA callbacks from the web • Universal model used by many services: GitHub, Slack, MailChimp, … • Pushing mechanism  asynchronous! • Implemented in various Office 365 Services • Microsoft Graph • Connectors • SharePoint
  • 5. #SPSNL17 - @eliostruyf WebHooks in SPO went GA in January 2017
  • 6. #SPSNL17 - @eliostruyf Where can you use them? • SharePoint • List • Libraries • Microsoft Graph • Messages, events, contacts, conversations in groups, OneDrive root items
  • 7. #SPSNL17 - @eliostruyf The good and the bad • WebHooks are asynchronous mechanism • Retry mechanism • 5 times with a delay of 5 minutes • More secure, no event information is passed • No support for event-ing events  only RER can be used • Add-ing, update-ing, delete-ing • Requires some setup, but once done, it is easy to maintain
  • 8. #SPSNL17 - @eliostruyf Remote event receivers vs WebHooks Remote event receivers • Synchronous (-ing) and/or async (-ed) • One request • One change = one request • Changes are inside the request body • 2 minutes to respond • Indefinitely • One try WebHooks • Async only • Retry logic: 5 times • Batched requests • Only notification  more secure • 5 seconds to respond • Needs subscription renewal • When it fails, you can try again later Both use the same base principle: call an external URI when something happens
  • 9. #SPSNL17 - @eliostruyf How to start using WebHooks?
  • 10. #SPSNL17 - @eliostruyf By subscribing to a WebHook! Notification service 1. Create a subscription 4. SharePoint responds with subscription info
  • 11. #SPSNL17 - @eliostruyf Important things about subscribing Subscribing: POST - /_api/web/lists/getbytitle('Title')/subscriptions { "resource": "https://tenant.sharepoint.com/sites/site/_api/web/lists/getbytitle('Title')", "notificationUrl": "Your notification service URL – HTTPS is required", "expirationDateTime": "Date value - maximum 6 months", "clientState": "String value for validation (optional)" }
  • 12. #SPSNL17 - @eliostruyf Important things about subscribing SharePoint calls your notification service: POST - https://notification-service?validationToken={random-guid} Respond with: Important: notification service needs to respond in < 5 seconds Status: 200 Body: validationtoken
  • 13. #SPSNL17 - @eliostruyf Important things about subscribing When validation is done, SharePoint returns the subscription information
  • 14. #SPSNL17 - @eliostruyf Local development and testing: ngrok - Secure tunnels to localhost https://ngrok.com/
  • 15.
  • 17. #SPSNL17 - @eliostruyf More about the notification service
  • 18. #SPSNL17 - @eliostruyf Notification service details • You choose the technology: Web API, Node.js, … • Respond in < 5 seconds and with status: 200-299 range • Retry mechanism  5 times (5 minute in between) • Not for the validation process • Receives minimal information, just a message “something” happened • Service has to gather the changes from SharePoint
  • 19. #SPSNL17 - @eliostruyf Minimal notification information?
  • 20. #SPSNL17 - @eliostruyf This is what you will receive { "value": [ { "subscriptionId":"2e7f9cd7-5cdb-4d57-b4d5-edc083202378", "clientState":null, "expirationDateTime":"2017-08-16T10:38:54.3440000Z", "resource":"465b36fc-e778-4047-8425-3f906497dfc3", "tenantId":"9fee8694-d491-4e3e-b10b-a81ee76dfad9", "siteUrl":"/sites/Webhooks", "webId":"e363e4e9-0161-495f-a652-15c618e2e963“ }] }
  • 21. #SPSNL17 - @eliostruyf How do I know what happened? • SPList.GetChanges method • POST - `/_api/web/lists(guid'${resource}')/getchanges` • Specify a change query + change token { "Item": true, "Add": true, "Update": true, "DeleteObject": true, "Restore": true, "ChangeTokenStart": { "StringValue": "1;3;465b36fc-e778-4047-8425-3f906497dfc3;636307008298500000;60877869" } } ChangeQuery properties: http://elst.es/2rib2q7
  • 22. #SPSNL17 - @eliostruyf Anatomy of the change token 1;3;465b36fc-e778-4047-8425-3f906497dfc3;636307008298500000;60877869 Version information (currently always 1) Scope of the change. 3 = List & library changes. Resource ID, can be retrieved from the subscription notification Timestamp in ticks Change number in the event cache table. You can start with -1.
  • 23. #SPSNL17 - @eliostruyf Using the change token • Using GetChanges without ChangeToken would return everything • By specifying a change token, you control what you need
  • 24. #SPSNL17 - @eliostruyf Things to know about the change token • First time, create it yourself (ex.: get all changes of the last hour) • Per GetChanges request, you get the latest change token • Store the latest change token, use it for the next call { "ChangeToken": { "StringValue":"1;3;465b36fc-e778-4047-8425-3f906497dfc3;636307074435230000;60879219" }, "ChangeType": 2, "SiteId": "1432d309-9f6a-4dae-8d35-532dec332b86", "ItemId": 3, … }
  • 25. #SPSNL17 - @eliostruyf GetChanges response value • Notice the ChangeType, it is an enumeration • 1 = added, 2 = updated, 3 = deleted { "ChangeToken": { "StringValue":"1;3;465b36fc-e778-4047-8425-3f906497dfc3;636307074435230000;60879219" }, "ChangeType": 2, "SiteId": "1432d309-9f6a-4dae-8d35-532dec332b86", "ItemId": 3, "ServerRelativeUrl":"", … "WebId":"e363e4e9-0161-495f-a652-15c618e2e963" } More information about the ChangeTypes - http://elst.es/2ruAfKn
  • 26. #SPSNL17 - @eliostruyf Supported event types • Added • Updated • Deleted • CheckedOut • CheckedIn • UncheckedOut • AttachmentAdded • AttachmentDeleted • FileMoved • VersionDeleted • FileConverted
  • 27. #SPSNL17 - @eliostruyf Creating your notification service
  • 28.
  • 29.
  • 30. #SPSNL17 - @eliostruyf Tokens, all about the OAuth tokens • Azure AD app registration • Generate a certificate • SharePoint requires access tokens with appidacr property set to 2 • Application Authentication Context Class Reference • 0 = Public client • 1 = Identified by a client id and secret • 2 = Identified by a certificate
  • 31. Azure AD application manifest Store this in a separate file (privatekey.pem) Fingerprint is also require to get the access token
  • 32.
  • 33. #SPSNL17 - @eliostruyf public getAppOnlyAccessToken(config: IConfig): Promise<any> { return new Promise((resolve, reject) => { const certificate = fs.readFileSync(path.join(__dirname, 'privatekey.pem'), { encoding : 'utf8'}); const authContext = new adal.AuthenticationContext(config.adalConfig.authority); authContext.acquireTokenWithClientCertificate(config.adalConfig.resource, config.adalConfig.clientID, certificate, config.adalConfig.fingerPrint, (err, tokenRes) => { if (err) { reject(err); } const accesstoken = tokenRes.accessToken; resolve(accesstoken); }); }); } Get an access token via a certificate and private key with ADAL for JS
  • 34. #SPSNL17 - @eliostruyf Important APIs • Retrieve all list / library subscriptions GET - /_api/web/lists/getbytitle('ListTitle')/subscriptions • Update a subscription PATCH - /_api/web/lists/getbytitle('ListTitle')/subscriptions('${subId}') Body: { "expirationDateTime": "New expiration date" } • Delete a subscription DELETE - /_api/web/lists/getbytitle('ListTitle')/subscriptions('${subId}')
  • 36. #SPSNL17 - @eliostruyf A real life setup and configuration SPO config page HTTP Triggered function Queue triggered function 1. Subscribe 2. Validate 3. Trigger change 4. Notify service 5. Put notification message on a queue6. Respond with 200 Use the page to: - Check subscriptions - Update subscriptions - Delete subscriptions 7. Trigger another Azure function that will do change handling 8. Retrieve latest change token10. Store latest change token
  • 37. #SPSNL17 - @eliostruyf Demo SPFx + Azure Functions
  • 38. #SPSNL17 - @eliostruyf Recap • Notification service has to respond in < 5 seconds • Retry mechanism  5 times (5 minute delay) • Not for the validation process • Subscription expiration date: 6 months • Create a check or renewal process in your subscription processor • You need to ask for the changes that happened  minimal information is send • Get the changes only what you are interested in • No synchronous events for SPO  event-ing events
  • 40. Office Servers & Services MVP Azure / Office 365 / SharePoint @eliostruyf www.eliostruyf.com info@estruyf.be Elio Struyf Lead trainer and architect
  • 41. #SPSNL17 - @eliostruyf Resources Certificate creation process with makecert - http://elst.es/2rhveZc Keycred GitHub - http://elst.es/2pW77vm All about the Change token - http://elst.es/2runG1M ChangeType enumeration - http://elst.es/2ruAfKn ChangeQuery properties - http://elst.es/2rib2q7 C# Sample application - http://elst.es/2qUYg0M Node.js / TypeScript sample application - http://elst.es/2qVpTqT or http://elst.es/2cycM82 SharePoint List WebHooks docs - http://elst.es/2qwl1as - http://elst.es/2quVjD0

Notes de l'éditeur

  1. https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-token-and-claims  appidacr