Question

How to capture payload of CONNECT API calls

As part of our requirement ,we want to capture the connector request and response into a table .We see that when a call is made from the Pega,the actual request is present in the parameter page in parameters "pyRequestHeaders","pyRequestData ,"pyRequestParameters" but we dont see the response captured in any parameter .How do we get the actual response that we are getting .Right now the only way i see we can do is to update the connector activity starting with name Invoke.Would also like to know what Pega recommends.

I see ,pyInvokeRESTConnector use below api function to make external connect call , Is there any parameter to capture actual JSON/XML response format that returns by external system ? . I think,read the value of pyObjName parameter(which holds data source page name) and convert the page into JSON .

tools.invokeConnector( primaryPage, stepPage, params );

Version :7.3.1

***Edited by Moderator Marissa to update platform capability tags****

Comments

Keep up to date on this post and subscribe to comments

July 19, 2019 - 9:02am

I don't see any parameter is being returned from below Pega api function so we don't have raw JSON in parameter page .

tools.invokeConnector( primaryPage, stepPage, params );

I just found the following work around to convert the response page to JSON.   

Below approaches may be helpful if payload of all Api's calls needs to be logged in dedicated table . If it's just debugging purpose then define the log level setting as DEBUG for com.pega.pegarules.integration.engine.internal.connect.rest.RESTConnector  . 

1) ClipboardPage Obj = tools.findPage(tools.getParamValue("pyObjName"));
Obj.getJSON(false));-------- we can't avoid pxObjClass in JSON message.

2) Create a JSON model data transform in @baseclass and pass parameter executionMode as SERIALIZE then it returns jsonData parameter .
 Additionally if any properties(like pxObjClass) to be eliminated in json response then define them in "Fields to skip when auto-mapping" in setting tab.

3) Using below snippet we can get the RAW JSON from response page but it's expecting to pass complete page reference like dataPage.response_PUT ( not taking top level page alone).

PublicAPI tools = pega_rules_utilities.getPublicAPI();
ServiceUtils utils = tools.getServiceUtils();
ParameterPage paramPage = tools.getParameterPage();

String sourcePgRef = tools.getParamValue("pyObjName")+".request";  /* for request */

ClipboardProperty mappingConfprop = tools.createPage("Rule-Connect-REST", "").getProperty("pyPUTRequestDataList");
ClipboardPage mappingConfPage = mappingConfprop.getPageValue(1);
mappingConfPage.putString("pyMapFrom", "JSON");
mappingConfPage.putString("pyMapFromKey", sourcePgRef);
mappingConfPage.putString("pyDataType", "String");
mappingConfPage.putString("pyParameterName", "OutboundData");
java.util.Map dataMap = new java.util.HashMap(3);
utils.mapOutboundData(mappingConfprop, dataMap, paramPage, mappingConfPage);

String RawJSON = (String)dataMap.get("OutboundData");
oLog.infoForced("*******outbound JSON ********* "+RawJSON);