Azure Function Apps – SharePoint lists – Creating web hooks that run PowerShell triggered by item creation

Recently I was asked to add a post about web hooks.

Thanks for taking the time to reply, I would love to see a STEP BY STEP implementation of a webhook specially how to automatically renew the expiry date of a subscription on a list. Azure functions implementation would be great.

So in this post I will attempt to answer the first part of the question from Keshav Taurah. Creating PowerShell Function Apps triggered by the creation of documents in SharePoint.

I will attempt to trigger a PowerShell script that is triggered by creating a SharePoint list item. While the web hook will renew the expiry date while it is being called.

First I’m going to reuse some of my work with Azure function apps that I created in one of my previous post:

https://veenstra.me.uk/2017/05/18/office-365-azure-running-pnp-powershell-using-azure-functions/

 

But this time I’m not going to use time as a trigger but the creation of a list item.

The above dialogue is slightly confusing. Did I just select Webhook and CSharp? Where is the PowerShell option?

You will have to click on the blue hyperlink, create your own custom functions and then filter by Language:

Ok, we want to go for HttpTrigger here.

Make sure that the Authorization is set to anonymous. Then click on create.

Once the Function is created, got to the Integrate options and select Selected Methods and untick all methods except for POST

Then go back to the function ( click on the function name in the left hand side and configure the function url:

 

This will give you a dialogue that gives you a url like this one:

https:/ /psazurefunctions.azurewebsites.net/api/HttpTriggerPowerShell1?code=ySrQW5k2GPFFje2s2hsJLvZe66dwhe6Lb51CCDyOFOpdMaEXsQOMkg==

keep a copy of the url that you get and we’re going to use this within Flow.

Creating a Flow in SharePoint

On a document library called Documents I’m now creating a flow which triggers on the creation of new documents being added to the library. Then a web hook is called (using the above url)

When checking in Azure I found that my function is called successfully:

So now my web hook is working.

 

 

Advertisements

4 thoughts on “Azure Function Apps – SharePoint lists – Creating web hooks that run PowerShell triggered by item creation

  1. Damn i followed a very lengthy and lot of coding way to achieve what you did in a few steps.Your the best mentor till date. “While the web hook will renew the expiry date while it is being called.” How is that working??

    Liked by 1 person

    1. Hi Keshav, I wonder if that expiry date is on webhooks on SharePoint lists only. I’m avoiding the webhook a bit by using Flow instead. I will check with Bert Jansen, the author of that article if this is the case.

      Like

Please leave a comment or feedback

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.