Azure Functions, SharePoint Webhooks and PnP - Part1

Posted 18 May 2017 12:00 AM by Ivan Chesa, Junior SharePoint Developer @ ClearPeople

I would like to show you how to use Azure Functions along with SharePoint WebHooks. Besides, I will show you how to use environmental variables (app settings) and code from external libraries (like the PnP Core) within the code of your Azure functions.

In this first post, I would like to show you how we can use Azure Functions as service endpoints for the SharePoint Webhooks subscriptions. I’ll guide you through the process to create a function and I will show you how to form the url that you must set as the endpoint in a webhook subscription.

I’m not going to explain how SP Webhooks work in this post, but you can visit this link for a better understanding of what SP Webhooks are.

To begin with, you are going to need to create a “Functions App” in Azure. To do this, enter to the Azure Portal and look for “Function App” in the Azure Marketplace:

AzureFunctions1

What you are doing is to create a special kind of App Service, but there is an important thing to notice. If you choose “Consumption Plan” as your Hosting Plan, you will pay only for the time that your functions are being executed. This is an interesting feature of the Azure Functions and it’s worth to use it.

AzureFunctions2

Now if you open the “Function Apps” blade you will find your app in there:

AzureFunctions3

In my case, I’ve created an app with the name “cpichesafunctions”. If you click in the app a “+” button next to the “Functions” will appear. Click on it and choose a template to start. Notice that you can create functions using different programming languages. This time, I’m going to choose C# as the language to use and I want a function of the kind HTTP trigger (there is a “GenericWebHook” template, but it doesn’t work good with SP WebHooks, however, this is just a template and you will write the code that you want). It is important to select “Anonymous” as the authorization level because SharePoint needs it.

AzureFunctions4

Next step is to configure your function (mine is “spwebhookfunction”). Click on “Integrate” and modify “Allowed HTTP methods”, “Mode” and “Selected HTTP methods” like in this image:

AzureFunctions5

Finally, you need the url that you are going to use as the webhook service endpoint. Click on your function to see the “workbench” screen. The code you see in there is the example that the template auto-generates (You will need to modify this to handle SharePoint notifications).

Click on “</> Get function URL” to see the url of your function, copy it in a notepad and add “?code=” at the end:

AzureFunctions6

Now click on the “Manage” button of your function and in the “Function Keys” section click on the “Click to show” link next to the “default” key to see the key:

AzureFunctions7

Add this key at the end of the url that you pasted in your notepad (the key is used to avoid unauthorized usage). What you have is the endpoint url that you must use for your webhook subscription and it should look like this:
"https://cpichesafunctions.azurewebsites.net/api/spwebhookfunction?code=<YOUR KEY>" 

In the next post, I will show a functional code example to be used as webhook service endpoint and I will explain what you must do to use environment variables (app settings) and external libraries in your Azure Functions code.​

Share:

Add your comment

 
 

 

Archive

Tagcloud

Digital Transformation employee engagement staff satisfaction productivity Microsoft Teams Office 365 Yammer cms content management system agile GDPR Microsoft Graph collaboration Microsoft sharepoint 2016 upgrade migration SharePoint Online 2016 Tech Trends Digital Disruption Context marketing marketing SharePoint 2010 SharePoint 2013 TFS Git security kentico Analytics intranet jquery QA Quality Assurance testing digital workspace content management websites Sitecore sitecore marketplace sitecore module cloud Microsoft Cloud Storage digital strategy technical consulting sitecore modules Experience database Sitecore 7 Sitecore 8 support account management customer experience Data Storage windows azure cms integration front end front end development prototype Cloud Storage StorSimple Front-end Development Layout SharePoint 2013 colour palette UI design website design log viewer sitecore cms website Azure big data business-critical sharepoint accessibility android apple chrome clear people clearpeople debug emulator ios mobile testing opera resize adobe desktop flash ie10 internet explorer 10 metro windows 8 bcsp SharePoint Advanced System Reporter reporting framework ControlMode form control master page placeholder publishing console SharePoint 2007 SharePoint error search search results search values software testing testing scenario audit content information architecture retention schedules PowerShell QuickLaunch scripts SharePoint server 2010 business solutions metalogix replication replicator storagepoint stena technet UK Technet picture library slideshow web part RTM released to manufacturing caml caml query MOSS 2007 query infopath