I spent some time to figure this out, so thought I would share.
We have a web job in Azure that runs a PowerShell-script that polls a list looking for new items, picks them up, creates a site collection and applies pnp templates. This works really 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.
It turns out that you can do this with the new Flow! Steps as follows:
- First you need the authentication tokens. Go to your App Service where you have the web job running, and click on Get publish profile
- 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”
- Then you need the web hook url. You find that by selecting your web job and clicking on properties.
- Go to the list from where you want to trigger the web job and create a new flow.
- The first step is to add a SharePoint action for “when an item is created”, and give the url to your site and your list as input.
- The next 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.
- The final flow should look like the following
That’s it! After an item is added to the list, your web job will trigger and start running. Happy coding!