This short post explains how to invoke UCS Director workflows via the northbound REST API. Authentication and role is controlled by the use of a secure token. Each user account within UCS Director has a unique API token, which can accessed via the GUI like so:
Firstly, from within the UCS Director GUI, click the current username at the top right of the screen. Like so:
User Information will then be presented. Select the ‘Advanced’ tab in order to reveal the API Access key for that user account.
Once retrieved, this key needs to be added as an HTTP header for all REST requests to UCS Director. The HTTP header name must be X-Cloupia-Request-Key.
Once this step is complete, the next requirement is to construct an appropriate URI for the HTTP request in order to invoke the required UCS Director workflow also supplying the required User Inputs (Inputs that would ordinarily be entered by the end user when executing the workflow manually).
UCS Director has two versions of northbound API. Version 1 uses HTTP GET requests with a JSON (Java Standard Object Notation) formatted URI. Version 2 uses HTTP POST with XML (eXtensible Markup Language) bodytext.
Workflow invocation for UCS Director uses Version 1 of the API (JSON). A typical request URL would look similar to this:
JSON formatted data consists of either dictionaries or lists. Dictionaries consist of name/value pairs that are separated by a colon. Name/value pairs are separated by a comma and dictionaries are bounded by curly braces. For example:
Lists are used in instances where a single value is insufficient. Lists are comma separated and bounded by square braces. For example:
To ease readability, it is often worth temporarily expanding the structure to see what is going on.
Now things get interesting. It is possible (And common) for dictionaries to contain lists, and for those lists to contain dictionaries rather than just elements (dog, cat, horse etc…).
With an understanding of how JSON objects are structured, we can now look at the required formatting of the URI for UCS Director. When invoking a workflow via the REST API, UCS Director must be called with three parameters, param0, param1 and param2. ‘param0’ contains the name of the workflow to be invoked. The syntax of the workflow name must match EXACTLY the name of the actual workflow. ‘param1’ contains a dictionary, which itself contains a list of dictionaries detailing each user input and value that should be inserted for that user input (As though an end user had invoked the workflow via the GUI and had entered values manually.
The structure of the UCS Director JSON URI looks like so:
So, let’s see this in action. Take the following workflow, which happens to be named ‘Infoblox Register New Host’ and has the user inputs ‘Infoblox IP:’,’Infoblox Username:’,’Infoblox Password:’,’Hostname:’,’Domain:’ and ‘Network Range:’.
The correct JSON object (Shown here in pretty form) would look like so:
Note once more, that the syntax of the input names must match EXACTLY that of the actual workflow inputs.
After removing all of the readability formatting, the full URL required in order to invoke this workflow with the ‘user’ inputs as shown above would look like this:
Now that we have our URL and authentication token HTTP header, we can simply enter this information into a web based REST client (e.g. RESTclient for Firefox or Postman for Chrome) and execute the request. Like so:
If the request is successful, then UCS Director will respond with a “serviceError” of null (No error) and the serviceResult will contain the service request ID for the newly invoked workflow:
Progress of the workflow can either be monitored by other API requests or via the UCS Director GUI:
Service request logging can also be monitored via either further API calls or via the UCS Director GUI: