SharePoint webhooks enable developers to build applications that subscribe to receive notifications on specific events that occur in SharePoint. When an event is triggered, SharePoint sends an HTTP POST payload to the subscriber. Webhooks are easier to develop and consume than SharePoint remote event receivers because webhooks are regular HTTP services (web API).
This article shows how to set up and use Azure Functions as your webhook for the SharePoint List changes.
Create SharePoint Lists
Create a SharePoint list named Countries to maintain country values.
Create a SharePoint list named WebHookHistory to keep track of the changes done in Countries list with the following columns:
Create Azure Function
Navigate to Azure Portal, select New, and then select Function App.
On the Basics page, complete the information needed to create the Function App
Select your hosting, monitoring settings, and then select Review + create to review the app configuration selections.
On the Review + create page, review your settings, and then select Create to provision and deploy the function app.
Select the Notification icon in the upper-right corner of the portal and watch for the Deployment succeeded message.
Select Go to resource to view your new function app.
After the function app is created, you can create functions in different languages.
Create an HTTP triggered function
Expand your new function app, select the + button next to Functions, choose HTTP Trigger
On the New Function page, complete the information needed to create the new Function
Configure Function Settings
Go to the Functions Apps blade and click on your Function. You will see an overview of the Function. Click on Platform features and click on Application settings
Update the configurations as shown below
Switch the Allowed HTTP methods to Selected methods, and then only allow the POST HTTP method. Also cross-check that Mode is equal to Standard, and Authorization level is set to Anonymous.
Include External DLL
Go to the Platform feature of the Functions App and click on Advanced tools (Kudu) to open the tool in another tab.
Click on Debug Console (CMD or PowerShell) and navigate to the wwwroot folder.
Create a new folder with name libraries and upload the necessary SharePoint DLLs in it
Copy Code Snippet
Replace the default function code with the following code:
Create List Subscription
Refer this Microsoft article to understand the API Endpoints and permission requirements.
We will need to let SharePoint know what webhook URL we are using. To do so, let’s start by copying the Azure Function URL.
To avoid unauthorized usage of your Azure Function, the caller needs to specify a code when calling your function. This code can be retrieved via the Manage screen.
So, in our case the webhook URL to use is the following:
azurefunctionurlvalue?code=functionkeyvalue
Let’s register the Function URL with the SharePoint List. In this example I am going to register my Azure Function with the list named Countries so that whenever a new item is added, the change details will be saved in WebHookHistory SharePoint list.
I used spo list webhook add CLI for Microsoft 365 command to register my azure function as webhook. Alternatively we can use SP Chrome Editor extension
Example:
o365 spo list webhook add –webUrl yoursiteurl –listTitle Countries –notificationUrl azurefunctionurlvalue?code=functionkeyvalue
Demo
I hope you find this post helpful.
Subscribe
Get the latest and greatest from me delivered straight to your inbox.