SPN + Azure Runbook + Webhook = Power BI Refresh (pt. 2)
In my previous post I described how to create an “Azure Based Black Box” able to run Power BI datasets refresh through API calls secured by SPN using PowerShell scripts in Azure Automation Runbook.
At this step is not possible to run this process without running the Runbook and in that case we should setup permission to each application in order to reach the specific Runbook and to run it.
Our aims are to lower the implementation and maintenance effort, to standardize the way we want this to be run giving an unique access point reachable to all the applications able to perform a post call.
Luckly Runbooks support webhooks.
What Wikipedia says about webhooks:
Webhooks are “user-defined HTTP callbacks”. They are usually triggered by some event, such as pushing code to a repository or a comment being posted to a blog. When that event occurs, the source site makes an HTTP request to the URL configured for the webhook. Users can configure them to cause events on one site to invoke behavior on another. Common uses are to trigger builds with continuous integration systems or to notify bug tracking systems. Because webhooks use HTTP, they can be integrated into web services without adding new infrastructure.
Basically we will create a webhook assigned to our Runbook and this will be called by applications with a POST call.
Specifying its expiration time, just one line of PowerShell is needed to create a webhook:
NB: as the warning says make sure to copy and save the URL that will be presented in this output window as you won’t be able to get it back from anywhere in the future.
Now you can call the Webhook from any application. In the following screenshot I’m performing a post call to that webhook using Postman, but you could use PowerShell or any kind of application you want.
The POST request will give you the Azure Automation Runbook Job Id assigned to your request.
Opening the Power BI portal I can verify refresh completed successfully.