ABX Action to Forwarding the payload to a REST Endpoint

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.

vRealize Automation Event Topics
vRealize Automation Event Topics

Once a subscription will create, you have to choose an event topic. Let’s say, we want to trigger a subscription in Deployment Requested.

Deployment requested event topic in a subscription
Deployment requested event topic in a subscription

The following parameters will be defined on Deployment requested stage of Deployment service.

KeyData TypeDescription
blueprintIdstringCloud template ID
blueprintVersionstringCloud template version
catalogItemIdstringCatalog item ID
catalogItemVersionstringCatalog item version
deploymentIdstringDeployment ID
eventTypestringDeployment request event type: CREATE_DEPLOYMENT / UPDATE_DEPLOYMENT / DESTROY_DEPLOYMENT
idstringDeployment request ID
requestInputscomplexDeployment request inputs
requestTypestringDeployment request type: BLUEPRINT / CATALOG
Deployment requested parameters

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

Leave a Reply

Your email address will not be published. Required fields are marked *