In this article, we will look at how to forward the machine payload to a REST endpoint with an ABX Action. If you want to trigger an ABX action, you can use the subscriptions in vRealize Automation Cloud. Subscriptions will trigger ABX Actions based on event topics.
You can see sample event topics below.
Once a subscription will create, you have to choose an event topic. Let’s say, we want to trigger a subscription in Deployment Requested.
The following parameters will be defined on Deployment requested stage of Deployment service.
Key | Data Type | Description |
blueprintId | string | Cloud template ID |
blueprintVersion | string | Cloud template version |
catalogItemId | string | Catalog item ID |
catalogItemVersion | string | Catalog item version |
deploymentId | string | Deployment ID |
eventType | string | Deployment request event type: CREATE_DEPLOYMENT / UPDATE_DEPLOYMENT / DESTROY_DEPLOYMENT |
id | string | Deployment request ID |
requestInputs | complex | Deployment request inputs |
requestType | string | Deployment request type: BLUEPRINT / CATALOG |
We can now choose an ABX Action but we have to create it. You can see a REST template below in Python.
def handler(context, inputs):
import requests
import json
import datetime as date
data = {
"inputs": inputs
}
now = date.datetime.now()
shortDate = now.strftime("%Y-%m-%d")
shortTime = now.strftime("%H:%M:%S")
payload = {
"id": inputs["id"],
"date": shortDate + " " + shortTime,
"data": data
}
baseURL = inputs["endpoint"]
headers = {
"Authorization": "Bearer XXxXX"
}
payload = json.dumps(payload)
response = requests.post(baseURL, data=payload, headers=headers)
print("Status Code " + str(response.status_code))
return str(response.status_code)
Don’t forget to add requests to dependency because FaaS Provider will install the library. If you don’t add you will see this error: “ModuleNotFoundError: No module named ‘requests’“. Also, you should add your REST endpoint as an input with ‘endpoint‘ key.
You can find the source code in my GitHub account as well.
https://github.com/umitdemirtas/abx-action-to-doing-rest-call
Hopefully, this post has been informative for you. If you have a question, opinion, or request about the article, you can contact us from the comments below or my email address. If you think this post is informative to others, be social, and share it on social media! Thank you for reading !!
1 thought on “ABX Action to Forwarding the payload to a REST Endpoint”