It has been a long journey and my article view count has reached the milestone of one million. Thanks to the entire C# Corner Team and the readers for the continued support.
In this article, we will see how to invoke Azure runbook using Webhook from Client Applications.
Azure Automation
Azure Automation enables users to automate tasks that are manual and repetitive in nature by using Runbooks. Runbooks are nothing but a set of tasks that perform some automated implementation in Azure Automation.
Runbooks in Azure Automation are based on Windows PowerShell or Windows PowerShell Workflow. We can code and implement the logic that we want to automate using PowerShell. You can see how to create runbooks and the practical scenarios from here
Webhook
A webhook allows us to start a runbook that we have created in Azure Automation using a single HTTP request. We can use the webhook from a variety of external services like GitHub, Visual Studio Team Services, and custom applications from which we can start Azure runbooks that helps us run some predefined logic. An overall webhook flow is shown in the below image. In this article we will see how to invoke the azure runbook using webhooks from various client applications.

Image Source : docs.Microsoft.com
Create a Webhook
We have already covered how to create the runbook in Azure and saw how to retrieve JSON Data from REST Endpoint and mail it to business users. Now we need a method to invoke the runbook remotely from our client application. We will be using Webhook for this purpose.
We can create a webhook from the Runbook page of the Azure Automation Account. Thus we can say that the webhook is hooked to a runbook upon its creation. Select the ‘Webhook’ option as shown below,

This will open up the page where we have to specify the below parameters that will be used to create the webhook:
- Name: Specify a name for the webhook
- Enabled: By default, it is enabled. If we disable it, we cannot access it from client applications. We can enable/disable it even after webhook creation.
- Expires: Every webhook comes with an expiration date beyond which it cannot be used. We can change once the webhook is created.
- URL : This is an important property of the webhoook as we will be using this URL to issue the POST HTTP request. The URL cannot be changed and contains a security token that enables the HTTP request to issue the call without any further authentication.
Note
We should note down the URL securely as it serves the purpose of a password. Any user having this URL can issue an HTTP POST request and run the runbook without any further authentication due to the presence of the security token in the URL. Moreover, we can see this URL only during the webhook creation time.

Click on OK to save the webhook parameters. The Webhook URL.
Click on Create to provision the runbook webhook.

Going to the runbook page, we can see that the webhook has been created.

Invoke the Runbook using Webhook from Client Applications
We can invoke a runbook using the webbook by issuing an HTTP Post request of the Webhook URL that we received while doing webhook creation. We can invoke the URL from a variety of client applications. We will see few examples in this section.
Invoke Webhook from PowerShell
We can invoke the Azure Runbook Webhook from the local machine using PowerShell. Ensure that we are using PowerShell 3.0 or above as ‘Invoke-RestMethod’ command is available only in the higher versions.

- $request = 'https://s3events.azure-automation.net/webhooks?token=GpU3Gd4E86eBzboUC5ptXl%2f9rXVP%2fuTdC16wJ1M4KsU%3d'
- $result = Invoke-RestMethod -Method Post -Uri $request
On running the above script from PowerShell we have invoked the webhook which triggered the runbook that get JSON Data from a REST endpoint and have mailed it to business user. The email screenshot is shown below,

Invoke runbook from C#









yogita yadavPosted Apr 3, 2020, 6:54 AM
I am trying to call runbook from angular client. But facing CORS issue. Can't enable CORS policy on runbook webhook. Any sample to call it from angular app