Support Article
Map base64 encoded response returned by Connect-REST call
Summary
A Connect-REST call is made to a Web service that returns an XML response that is in base64 encoded format. The requirement is to map the base64 encoded response to the required response data model on the Pega application.
Error Messages
Not Applicable
Steps to Reproduce
Not Applicable
Root Cause
An issue in the custom application code or rules.
Resolution
Follow the below example to map an XML response encoded in base64 format that is returned by a REST Web Service:
<?xml version="1.0" encoding="UTF-8"?>
<animals>
<animal type="birdType">
<name>lion</name>
<origin>123</origin>
<color>yellow</color>
</animal>
<animal type="fishType">
<name>tiger</name>
<origin>1234</origin>
<size>20</size>
</animal>
</animals>
The Base64 encoded string for the above Response XML is as below
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPGFuaW1hbHM+CjxhbmltYWwgdHlwZT0iYmlyZFR5cGUiPjxuYW1lPmxpb248L25hbWU+PG9yaWdpbj4xMjM8L29yaWdpbj48Y29sb3I+eWVsbG93PC9jb2xvcj48L2FuaW1hbD4KPGFuaW1hbCB0eXBlPSJmaXNoVHlwZSI+PG5hbWU+dGlnZXI8L25hbWU+PG9yaWdpbj4xMjM0PC9vcmlnaW4+PHNpemU+MjA8L3NpemU+PC9hbmltYWw+CjwvYW5pbWFscz4=
4. Map the response to a string property as the endpoint returns the response in a base64 encode string format.
6. Use the Apply-Parse-XML method in the same activity to map the converted XML string to the Clipboard properties in the Integration Layer. The Parse-XML rule used in the activity is the same Parse XML rule which the Create-REST Integration wizard generated in Step 2.
In the below example, the @pxExecuteAnActivity(DataSource,Animals) function invokes the 'Animals' activity that is created in the Integration Layer in Step 3.
Below is the result for the data page (D_Animals) execution:
Published November 25, 2019 - Updated December 2, 2021
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.