In a previous article, I taught you how to explore and use the REST API to start a Workflow using a generic browser based REST Client. In this article, I will provide a Python based example of running the “Create a Record” workflow that was created in Part 2 of my SQL Plug-in Dynamic Types Simple CMDB for vCACarticle. Since I’m not even close to being proficient with Python, this will be a very short article! You may download the script in this article from my vroClientScripts Repository on GitHub. Be sure to check out that repo because my colleague has provided a better written Python module there for calling workflows.
In my efforts to figure out how to consume a REST API using Python, I found the following sites helpful:
In particular, be sure you have a functional Python install with the “requests” module installed and ready to use. From what I can tell, the “json” module is part of the recent Python versions so no extra step should be required to install that.
The following code should be saved as something like runWorkflow.py:
Note: Before attempting to run the script, be sure to modify the parameters at the beginning of the script to reflect YOUR workflow.
I have kept the script as simple as I can, including the option to NOT Verify the SSL Certificate so that self-signed certs do not prevent the script from running.
The json file
While testing this, my example workflow was the “Create a Record” workflow as noted earlier. That workflow had a number of inputs so these were loaded into a json file. In order to learn more about how to get the correct input json for your workflow, please reference my article: How to use the REST API to Start a Workflow.
Here’s my example json file:
I ran the following from my Windows desktop command prompt:
When I check the Orchestrator client, I can see that the workflow has run and completed successfully (See screenshot above!)
Help Me Make This Sample Better!
As noted at the beginning of this article, I don’t know Python but I managed to get a very simple example script working here. Please submit your comments and/or improvement suggestions to help increase the value and usefulness of this simple script.
- Get credentials from a hidden config file
- Pass in all parameters as command line arguments
- Display/parse output