POST API call using APAMA script

64 views Asked by At

I want to develop a APAMA script that will trigger a cumulocity POST API call to add a manage object inside device as a childAsset.

API : https://cti.ram.m2m.telekom.com/inventory/managedObjects/{device-id}/childAssets

Payload : {
  "managedObject": {
    "id": "<manage object id>"
  }
}

Please share thought or code snippet as I am completely new to APAMA.

1

There are 1 answers

0
Suresh On BEST ANSWER

Apama does support an API that can be used to invoke the Cumulocity IoT REST API. check the doc for details: https://documentation.softwareag.com/pam/10.15.3/en/webhelp/pam-webhelp/#page/pam-webhelp%2Fco-ConApaAppToExtCom_cumulocity_invoking_other_parts_of_the_cumulocity_rest_api.html%23

EPL example for your question:

string parentDeviceID := 12232;
string childDeviceID:= 343222;

GenericRequest request := new GenericRequest;
request.reqId := com.apama.cumulocity.Util.generateReqId();
request.path := "/inventory/managedObjects/"+parentDeviceID+"/childAssets";
request.method := "POST";
request.body := {
    "managedObject": {
        "id": childDeviceID
    }
};
request.isPaging := false;
request.headers := {"accept": "application/json"};
send request to GenericRequest.SEND_CHANNEL;

monitor.subscribe(GenericResponse.SUBSCRIBE_CHANNEL);
on GenericResponseComplete(reqId=request.reqId)
{
    monitor.unsubscribe(GenericResponse.SUBSCRIBE_CHANNEL);
}

on GenericResponseComplete(reqId=reqId) as resp {
        if resp.error {
            log "request failed to adding child : " + resp.statusCode.toString(), + " , error: "+  resp.details;
        }
}