Question
DCS
GB
Last activity: 6 Sep 2024 11:08 EDT
How to Capture Outbound REST API Calls from Pega to external systems for Auditing?
When working with Pega, capturing outbound REST API calls for auditing purposes can be a challenge. In this post, we’ll explore a generalized solution to address this issue. We’ll focus on the latest Pega versions, where direct methods for capturing raw request and response messages in connect-Rest calls are not readily available.
As i am aware, there is no straightforward mechanism to capture the raw request and response messages for connect-Rest calls. Even after scouring the Pega documentation and various support articles, users often find themselves without a clear solution (apart from converting pega page to json). However, got a workaround that involves setting Param.storeRawMessage=true
before making the connect-Rest API call. This trick, shared by Dmitry (though not documented officially), allows you to capture the request and response payloads. We could see the Raw message from Clipboard, screenshot is attached.
When working with Pega, capturing outbound REST API calls for auditing purposes can be a challenge. In this post, we’ll explore a generalized solution to address this issue. We’ll focus on the latest Pega versions, where direct methods for capturing raw request and response messages in connect-Rest calls are not readily available.
As i am aware, there is no straightforward mechanism to capture the raw request and response messages for connect-Rest calls. Even after scouring the Pega documentation and various support articles, users often find themselves without a clear solution (apart from converting pega page to json). However, got a workaround that involves setting Param.storeRawMessage=true
before making the connect-Rest API call. This trick, shared by Dmitry (though not documented officially), allows you to capture the request and response payloads. We could see the Raw message from Clipboard, screenshot is attached.
Now, here’s where things get interesting. After successfully capturing the raw response using the method step-page, i encountered a roadblock. The pyRawMessage
property, which contains the raw response data, isn’t directly accessible for reading. But tried an alternative technique involving Java code that captures the raw message.
//String request = myStepPage.getStringIfPresent("pyRawMessage");
ClipboardPage cp = tools.findPage("UKPostcodeGetPage");
ClipboardProperty request = cp.getProperty("pyRawMessage");
oLog.infoForced("Request-->>"+request.getStringValue());
pega_rules_utilities.sendDebugMessageToTracer("Request-->>"+request.getStringValue(),"MyRS");
Have you faced this behavior in Pega? Do you know why pyRawMessage
remains elusive? Perhaps you’ve discovered other clever ways to capture the connect-rest response in its raw, unadulterated form (without converting it to a JSON string)? Looking forward to hearing from the experts.
Thanks,
Nanjundan Chinnasamy | Pega Lead Decision Architect | 1:1 Customer Engagement
-
Reply
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Updated: 15 May 2024 7:57 EDT
Cognizant
IN
@Nanjundan Chinnasamy I have the done the same approach to get the raw response coming from the API but there's one difference in how I have implemented. The property pyRawMessage is present in 'Embed-Error' class. So, I have created a named page of that class and copied the API response page to it. Post this the property was accessible via normal 'set' or 'property-set'.
Post reading your approach on how to extract the property, I got back a bit on why I didn't think of that even when I used same in some scenarios which would reduce a duplicate copy of same data (even though we are remove at the end of the logic.). So, I have tried it with an OOTB function and it worked (in the above snapshot). @PegaSurveyUtilities.getPropertyValueFormPage(tools,Param.DataSource,"pyRawMessage"). Thanks you for posting your approach. But if its a new implementation of the API, we can go with mapping the response to clipboard property and use that as source since it'll also be having the same data.
Pegasystems Inc.
CA
I rely on the logs to capture the requests and responses for Connect-REST APIs. This will be challenging if you have multiple nodes because you have to scan through all the nodes.
Log category
pxIntegration.Connector.REST DescriptionIntegration REST connector log category Loggerscom.pega.pegarules.integration.engine.internal.connect.rest.RESTConnector com.pega.pegarules.integration.engine.internal.connect.http.HTTPClientUtils com.pega.platform.integrationcore.client.http.internal.ComponentsHttpClient org.apache.http.wire Rule_Obj_Activity.Invoke.Rule_Connect_REST.Action |
DCS
GB
Hi @RameshSangili,
We need to capture the raw-payload messages to the DB tables for auditing purposes as i mentioned above, enabling loggers would help us to log the outbound API messages in the logger file which is not required. Hope this clarifies.
Thanks, Nanjundan Chinnasamy
Ai4process
GB
To capture the raw JSON response, instead of setting 'param.stroeRawMessage=true', you can try mapping the response in the connector rule response tab. Select "Map to" as "Clipboard" and "Map to key" as ".pyResponseData". This will capture the raw JSON response in 'pyResponseData'. You can then experiment with 'pyResponseData'. Please note that 'pyRawMessage' and 'pyResponseData' are essentially the same type of properties, with a difference in their apply to class. Perhaps you could give a try this.
Accepted Solution
Updated: 15 May 2024 7:57 EDT
Cognizant
IN
@Nanjundan Chinnasamy I have the done the same approach to get the raw response coming from the API but there's one difference in how I have implemented. The property pyRawMessage is present in 'Embed-Error' class. So, I have created a named page of that class and copied the API response page to it. Post this the property was accessible via normal 'set' or 'property-set'.
Post reading your approach on how to extract the property, I got back a bit on why I didn't think of that even when I used same in some scenarios which would reduce a duplicate copy of same data (even though we are remove at the end of the logic.). So, I have tried it with an OOTB function and it worked (in the above snapshot). @PegaSurveyUtilities.getPropertyValueFormPage(tools,Param.DataSource,"pyRawMessage"). Thanks you for posting your approach. But if its a new implementation of the API, we can go with mapping the response to clipboard property and use that as source since it'll also be having the same data.
Pegasystems Inc.
AU
@Sangeeth, Nanjundan Chinnasamy is it expected set Param.storeRawMessage = true in the request DT of Data page that is using connector as source? I have been trying to test this in lab in 24.1 release and do not see pyRawMessage populated
Pegasystems Inc.
AU
@Sangeeth Yes that is correct. The Request Data Trasform in Data Page is used to set Param.storeRawMessage = true
In the tracer I can see the parameter is passed to pxCallConnector Activity which further invokes Rest connector. Whereas the DataSource page retruned in reponse DT do not have pyRawMessage. Only following is listed
Banco Santander Brasil SA
BR
To get a response Json you can configure in the connector rule response Message Data “Map to” Clipboard and ”Map to key” a string property (.pyResponseData as an example) and then you can always get the whole JSON from this property. After this, you can map JSON to Pega properties by a data transform JSON .
Updated: 5 Sep 2024 12:35 EDT
Infosys
IN
Hi @Nanjundan Chinnasamy, As you mentioned when Param.storeRawMessage=true is set before Connect-Rest. I am able to see pyRawMessage with response JSON only. Where can I find the JSON for request on tracer. Thanks in advance.
Updated: 5 Sep 2024 12:26 EDT
Cognizant
IN
@Pavan_S Please use the code(function) in the attachment to get the request JSON.
Updated: 6 Sep 2024 11:08 EDT
Infosys
IN
Hi @Sangeeth I am restricted to use custom function, I am able to see the pyRequestData on the Param Page. But I am unable to access it through the Property-Set. Is there any other approach to fulfill my requirement?
Infosys
IN
Hi @Sangeeth. If the only way to access the pyRequestData is custom code, Do you want me to create and function with the above code attached or use java step and use this function. Can you please let me know? Any screenshots for reference. Please let me know. Thanks in advance.
Updated: 6 Sep 2024 10:52 EDT
Cognizant
IN
@Pavan_S Create a function and call that function in response DT Function: Usage: