Step-by-Step Guide: Real Time Currency Conversion using SAP Integration Suite (CPI)

Estimated read time 9 min read

Introduction

In real-world integration scenarios, integrations are never limited to just data movement. Very often, they also involve business logic that needs to be accurate, reliable, and understandable for non‑technical users. One such recurring requirement encounters is currency conversion.

Whether it’s for reporting, billing, or analytics, converting currency values accurately and in real time is an important requirement.

In this blog, I will be sharing a real‑time currency conversion iFlow that I designed and implemented using SAP Integration Suite (CPI). This solution uses an external currency exchange‑rate API (RapidAPI) and delivers the result in a clean, email‑friendly output, along with robust exception handling.

Business Scenario

The scenario is straightforward but very realistic:

A source system sends an amount in one currencyA target system expects the amount in another currencyThe exchange rate must be live and reliableThe final output should be human‑readable and user friendly, not just raw JSON

At the same time, the integration should not break silently when:

Mandatory fields are missingThe input payload is malformedThe external API is downAny runtime exception occurs

This Integration scenario strictly follows all the mentioned points and ensures that it give accurate results and handle errors efficiently.

Input Payload (Source System to CPI)

The source system (ie, Postman) sends a simple JSON payload:

Mandatory Fields

sourceCurrency – currency to convert FromtargetCurrency – currency to convert TosourceAmount – amount to be converted

NOTE:

I have made a conscious decision to treat all three as mandatory.
If even one is missing, the message is rejected immediately and routed to the Exception Subprocess.

High‑Level Architecture

The integration flow consists of:

HTTPS Sender – receives the request Content Modifier – stores RapidAPI host and key securely Groovy Script – validates input and extracts fields Request Reply – calls external exchange‑rate API JSON to XML Converter – prepares response for XSLT  XSLT Mapping – beautifies output into HTML Mail Adapter – sends result to user Exception Subprocess – handles all runtime failures

STEP 1: HTTPS Sender – Entry Point of the Integration Flow

The integration flow begins with an HTTPS Sender Adapter, which acts as the entry point for the entire currency conversion process.

Purpose of HTTPS Sender

Exposes the iFlow as a secure REST endpointReceives the input JSON payload from the source system (Postman)

Secure by default and commonly used in real projects for inbound APIs

STEP 2: Content Modifier – Managing API Credentials

Instead of hard‑coding the RapidAPI host and key inside a Groovy script, I stored them as headers in a Content ModifierIt makes the integration much more maintainable.
Credentials are easy to changeScripts remain cleanNo risk of accidentally logging secrets

STEP 3: Groovy Script – Input Extraction & Validation

The Groovy script performs hard validation for the incoming payload.

Here is the Groovy Script:

 So in this Groovy script, I have :

Parsed the JSON explicitlyChecked each mandatory fieldStored valid values as Exchange PropertiesThrows a meaningful exception if any field is missing

This hard validation is crucial because CPI does not throw errors for missing JSON fields by default.

Because of this, invalid messages are stopped immediately and routed to the Exception Subprocess 

STEP 4: Request Reply – Calling the Exchange Rate API

The Request Reply step dynamically calls the external RapidAPI Currency Exchange endpoint using:

Source currencyTarget currencySecure headers from the Content Modifier

And If the API:

Times outReturns an errorIs unreachable

Exception Subprocess handles the failure gracefully.

STEP 5: JSON to XML Converter

Since XSLT only works with XML, so i converted the API’s JSON response into XML.

This made:
Mapping easier
Formatting predictable

Transformation logic much cleaner

STEP 6: XSLT Mapping – Beautified HTML Output

Here is the XSLT Script:

 
Instead of returning raw API data in JSON, I used XSLT to generate a beautiful modern HTML card, optimized for email clients.

Features that i have focused for beautification includes:

A green glowing success card Currency symbols Proper decimal formatting Email‑safe inline CSS Readable and user friendly

STEP 7: Mail Adapter – Delivering the Result

The Mail Adapter sends:

The formatted HTMLClean layoutNo broken stylingCompatible with Outlook, Gmail, mobile clients

STEP 8: Exception Subprocess – For Error Handling

 

The Exception Subprocess ensures there are no silent failures and handles errors effectively.

Here’s what the Groovy script does:

Captures runtime errorsIdentifies what actually went wrongCategorizes the error:Missing mandatory fieldsMalformed JSONExternal API failureScript execution errorGenerates modern card formation using HTML for Beautification 

Here what the Error Mail Adapter does:

Send a structured and well formatted HTML error email, just like as for success mail

Success Email Output:

Gives successful currency conversion information dynamically

Error Email Output:

Gives Error message and its possible causes in case of any error

Key benefits of this approach 

Robust mandatory field validationSecure credential handlingProfessional, email‑ready outputUser‑friendly error messagesReusable iFlow pattern for other APIsFully Externalized Parameters 

Conclusion

This currency conversion iFlow shows how SAP Integration Suite can be used for much more than just routing messages.

I was able to build an integration that is stable, readable, and production‑ready.

This implementation helped me better understand how to design flexible and maintainable integration flows, especially when dealing with real-world requirements.

I hope this experience helps others who are working on similar scenarios in SAP Cloud Integration.

If you found this blog helpful:

Like the blogShare it Feel free to comment or ask questions

Happy Integrating !

 

​ IntroductionIn real-world integration scenarios, integrations are never limited to just data movement. Very often, they also involve business logic that needs to be accurate, reliable, and understandable for non‑technical users. One such recurring requirement encounters is currency conversion.Whether it’s for reporting, billing, or analytics, converting currency values accurately and in real time is an important requirement.In this blog, I will be sharing a real‑time currency conversion iFlow that I designed and implemented using SAP Integration Suite (CPI). This solution uses an external currency exchange‑rate API (RapidAPI) and delivers the result in a clean, email‑friendly output, along with robust exception handling.Business ScenarioThe scenario is straightforward but very realistic:A source system sends an amount in one currencyA target system expects the amount in another currencyThe exchange rate must be live and reliableThe final output should be human‑readable and user friendly, not just raw JSONAt the same time, the integration should not break silently when:Mandatory fields are missingThe input payload is malformedThe external API is downAny runtime exception occursThis Integration scenario strictly follows all the mentioned points and ensures that it give accurate results and handle errors efficiently.Input Payload (Source System to CPI)The source system (ie, Postman) sends a simple JSON payload:Mandatory FieldssourceCurrency – currency to convert FromtargetCurrency – currency to convert TosourceAmount – amount to be convertedNOTE:I have made a conscious decision to treat all three as mandatory.If even one is missing, the message is rejected immediately and routed to the Exception Subprocess.High‑Level ArchitectureThe integration flow consists of:HTTPS Sender – receives the request Content Modifier – stores RapidAPI host and key securely Groovy Script – validates input and extracts fields Request Reply – calls external exchange‑rate API JSON to XML Converter – prepares response for XSLT  XSLT Mapping – beautifies output into HTML Mail Adapter – sends result to user Exception Subprocess – handles all runtime failuresSTEP 1: HTTPS Sender – Entry Point of the Integration FlowThe integration flow begins with an HTTPS Sender Adapter, which acts as the entry point for the entire currency conversion process.Purpose of HTTPS SenderExposes the iFlow as a secure REST endpointReceives the input JSON payload from the source system (Postman)Secure by default and commonly used in real projects for inbound APIsSTEP 2: Content Modifier – Managing API CredentialsInstead of hard‑coding the RapidAPI host and key inside a Groovy script, I stored them as headers in a Content Modifier. It makes the integration much more maintainable.Credentials are easy to changeScripts remain cleanNo risk of accidentally logging secretsSTEP 3: Groovy Script – Input Extraction & ValidationThe Groovy script performs hard validation for the incoming payload.Here is the Groovy Script: So in this Groovy script, I have :Parsed the JSON explicitlyChecked each mandatory fieldStored valid values as Exchange PropertiesThrows a meaningful exception if any field is missingThis hard validation is crucial because CPI does not throw errors for missing JSON fields by default.Because of this, invalid messages are stopped immediately and routed to the Exception Subprocess STEP 4: Request Reply – Calling the Exchange Rate APIThe Request Reply step dynamically calls the external RapidAPI Currency Exchange endpoint using:Source currencyTarget currencySecure headers from the Content ModifierAnd If the API:Times outReturns an errorIs unreachableException Subprocess handles the failure gracefully.STEP 5: JSON to XML ConverterSince XSLT only works with XML, so i converted the API’s JSON response into XML.This made:Mapping easierFormatting predictableTransformation logic much cleanerSTEP 6: XSLT Mapping – Beautified HTML OutputHere is the XSLT Script: Instead of returning raw API data in JSON, I used XSLT to generate a beautiful modern HTML card, optimized for email clients.Features that i have focused for beautification includes:A green glowing success card Currency symbols Proper decimal formatting Email‑safe inline CSS Readable and user friendlySTEP 7: Mail Adapter – Delivering the ResultThe Mail Adapter sends:The formatted HTMLClean layoutNo broken stylingCompatible with Outlook, Gmail, mobile clientsSTEP 8: Exception Subprocess – For Error Handling The Exception Subprocess ensures there are no silent failures and handles errors effectively.Here’s what the Groovy script does:Captures runtime errorsIdentifies what actually went wrongCategorizes the error:Missing mandatory fieldsMalformed JSONExternal API failureScript execution errorGenerates modern card formation using HTML for Beautification Here what the Error Mail Adapter does:Send a structured and well formatted HTML error email, just like as for success mailSuccess Email Output:Gives successful currency conversion information dynamicallyError Email Output:Gives Error message and its possible causes in case of any errorKey benefits of this approach Robust mandatory field validationSecure credential handlingProfessional, email‑ready outputUser‑friendly error messagesReusable iFlow pattern for other APIsFully Externalized Parameters ConclusionThis currency conversion iFlow shows how SAP Integration Suite can be used for much more than just routing messages.I was able to build an integration that is stable, readable, and production‑ready.This implementation helped me better understand how to design flexible and maintainable integration flows, especially when dealing with real-world requirements.I hope this experience helps others who are working on similar scenarios in SAP Cloud Integration.If you found this blog helpful:Like the blogShare it Feel free to comment or ask questionsHappy Integrating !   Read More Technology Blog Posts by Members articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author