Trigger an Azure web job from Microsoft Flow in Office 365

I spent some time figuring this out at the Office365/SharePoint hackathon Arctic SharePoint Challenge so thought I would share, as I didn’t find anyone having done exactly this before.

My use case is that you have a web job in Azure that runs a PowerShell-script that polls a list in a SharePoint site in Office 365 looking for new items. After new items arre added, the job picks them up, creates site collections and applies pnp templates. This works well as a scheduled job, but it would be nicer if we could trigger the job automatically so we don’t have to wait for the scheduled start time. Of course, this approach should work for any type of web job, as long as it has the web hook endpoint.

It turns out that you can trigger the web job with Flow! The steps are as follows:

  1. First you need the authentication tokens. Go to your App Service where you have the web job running, and click on Get publish profile 
  2. In that file, look for the publishprofile with publishMethod=”MSDeploy”. You need the userName and userPwd. E.g. in my case it was userName=”$ASPC2017″ userPWD=”LBxk5ttrvZTgAM7msxDGRZA0hy9Wws3gdNeuK33hacB52SSaAQRslmuzshzi”
  3. Then you need the web hook url. You find that by selecting your web job and clicking on properties.
  4. Go to Flow (e.g. via the list from where you want to trigger the web job) and create a new flow.
  5. The first flow step is to add a SharePoint action for “when an item is created”, and give the url to your site and select the list you want to use as input.
  6. The second flow step is to add an HTTP-action. Choose method POST, add the Uri to the web hook url. You don’t need to set headers and body. Choose Basic authentication and use the username and password from step 2.
  7. The final flow should look like the following 

That’s it! After an item is added to the list, your web job will hopefully trigger and start running. Hope this is helpful to someone.

2 thoughts on “Trigger an Azure web job from Microsoft Flow in Office 365”

  1. Hi,

    Thanks for sharing. One question though.
    Above approach works fine when single item is added at a time. When webjob is running, meantime if new item is added/updated to list, It gives error like “Cannot start a new run since job is already running”. Is there any easy way to handle this ?. Thank you in advance!.


  2. Hello Tarjei,
    Thanks for the only solution I found on the internet to trigger an Azure Webjob.
    But yet, something is highly disturbing me…
    You store your webjob’s username and user password roughly in your Flow !
    So, is it possible to have a workaround on that ? Like using another action? Or better, using a custom connector in Flow.
    Thanks for your time and answer !

Leave a Reply

Your email address will not be published. Required fields are marked *