How to retrieve data from the Cost and Benefit Analysis section of Automation Hub using Rest API and Python?
Issue Description: In the Cost and Benefit Analysis section of Automation Hub, start, end date, etc. for different phases of the project can be entered. Is there any way to read this data through Rest API endpoints, specifically in the launch and end date, with provision to read all dates values.
Resolution: For this requirement, use the existing Open Api for Automation Hub
- In order to see which endpoints are available for your Automation Hub, you can open your Swagger
- Generate the Open API token details in order to access the resource details.
- For this go to Automation Hub -> Admin Console -> Platform Setup -> Open API -> Generate Token
- In the end, the needed details like in the below screenshot will be obtained
Note: Bearer token is the Tenant ID/Token
Example: Bearer d29d4c5e-8118-4930-8146-a987b1113c71/bb67df5a-c3cc-43e1-ae98-c4960615f789
x-ah-openapi-app-key is your App Key
x-ah-openapi-auth is always openapi-token
- Assuming the scenario, Workspace -> Automation Pipeline -> select one automation -> View Automation Profile -> Cost Benefit Analysis -> and to see in a Rest API call the Launch Date value for the Actual & New Estimate section
Perform a request for Get CBA API call.
Get CBA -> One of the most important aspects of your automation pipeline is seeing the Return on Investment, which you can easily find and manage on the Cost Benefit Analysis page from Automation Hub.
Using the Get CBA API call, you are able to get the Cost Benefit Analysis data from a specific Automation.
The Get CBA supports a single filter, which is the automation ID.
- 'id' = the ID of the Automation*
*In order to get the ID of an Automation, you need to use the Get Automations API request.
- Build the request to get the id from /api/v1/openapi/automations REST API endpoint
For example, retrieving the details for the process with the name: Onboarding of new employee
- Perform a GET action for URL: https://URL/ACCOUNT_NAME/TENANT_NAME/automationhub_/api/v1/openapi/automations?advanced_information=true&highLevelAssessment=true&s=Onboarding of new employee
Authorization:
Type: Bearer Token with value Tenant ID/Token
Headers:
Accept is application/json
x-ah-openapi-app-key is your App Key
x-ah-openapi-auth is always openapi-token
In the body response, retrieve the value for process_id (in this example is 1)
- Build the request to get the cba details from /api/v1/openapi/cba REST API endpoint:
Perform a GET action for URL: https://URL/ACCOUNT_NAME/TENANT_NAME/automationhub_/api/v1/openapi/cba?id=1
Authorization:
Type: Bearer Token with value Tenant ID/Token
Headers:
Accept is application/json
x-ah-openapi-app-key is your App Key
x-ah-openapi-auth is always openapi-token
- In order to get start_date and end_date values only for the Launch Date, use for example a Python script to manipulate the received JSON response.
For example:
import requests import json url = 'https://YOUR_URL_ADDRESS/ACCOUNT_NAME/TENANT_NAME/automationhub_/api/v1/openapi/cba?id=ID_NUMBER_OF_YOUR_PROCESS' payload={} tenant_id = 'YOUR_TENANT_ID' token = 'YOUR_TOKEN' app_key = 'YOUR_APP_KEY' token_for_headers = str(tenant_id + '/' + token) headers = { 'accept': 'application/json', 'x-ah-openapi-auth': 'openapi-token', 'x-ah-openapi-app-key': app_key, 'Authorization' : 'Bearer ' + token_for_headers} response = requests.request("GET", url, headers=headers, data=payload) pretty_response = json.dumps(response.json(), indent=4) needed_results = json.loads(pretty_response) #print(pretty_response) print(str(needed_results['data']['sections'][0]['sections'][2]['title'])) print(str(needed_results['data']['sections'][0]['sections'][2]['input_fields'][4]['field_name']) + ' -> start date: ' + str(needed_results['data']['sections'][0]['sections'][2]['input_fields'][4]['start_date']['value'])) print(' -> ' + 'end date: ' + str(needed_results['data']['sections'][0]['sections'][2]['input_fields'][4]['end_date']['value']))
Results: