Invoking SMA Runbooks via REST

Service Management Automation Runbooks are PowerShell workflows. Workflows allow parameters to be passed in at the time of execution and are essential to any infrastructure automation.

Service Management Automation runbooks can be initiated through the Azure web portal which creates appropriate input fields for the data types used in the “param” section of the workflow. With the workflow above, two string input fields are displayed that match the “FIRSTNAME” and “LASTNAME” variables.

Invoking this runbook via REST (starting directly via a submitted web POST) requires the runbook GUID, then a POST request can be sent to the Orchestrator web service containing parameter information. The GUID for my runbook can be obtained by making a GET request directly from the hosting Service Management Automation server. With the URL below you can see how a request for runbook details is made, filtered by the name "runbookparametersexample".

Remember that spaces and special characters are translated when they are included in a URL so “%20” is a space an “%27” is a single quote mark. Web Browsers will translate these characters automatically so

The submitted Job may be viewed via the SMA / Azure portal… as expected, the passed parameters have been processed as expected.

If we were calling runbooks from a Windows host, we could simply use PowerShell cmdlets to do the same thing. PowerShell will be quietly querying the SMA web service to find the runbook GUID and it will create the JSON body for a request just as above.

As Service Management is integrating a wide range of technologies, it’s important to know how the requests are formed without using Windows based cmdlets.

Name Value Pairs

The web service (port 9090) is documented by Microsoft to accept “Name Value Pairs” as parameters when invoking runbooks. With the example of passing two text fields, calling a runbook is without issue.

The use of different data types allows the web portal to provide a rich interface based purely on the type of parameter being used. The Microsoft example shows how date controls, buttons and string (and integer) fields can be called for and presented to the person initiating the script.

If we construct a POST request, using JSON and listing “Name Value Pairs” with the Sample-Using-RunbookParameters example, we quickly discover that data types other than strings cause exception errors.

The “Catch 22” is that SMA (on port 9090) only currently supports the initiation of runbooks using Name Value Pairs (Orchestrator.ResourceModel.NameValuePair). For coders, Name Value Pairs are a type of list or a dictionary of string values. All names and values are passed as strings and there is no third field to declare what type of data they are supposed to represent. As a result, by only supporting Name Value Pairs for runbook inputs, runbooks are forced to only use string inputs when processes are to be initiated via REST.