Foreign exchange rates interface (NBP)


One of the most common and typical requirements one can get during implementation projects is to create an interface allowing to update foreign exchange rates based on data provided by national bank. Below you will find a simple step-by-step tutorial explaining how to create one with an example of polish central bank (NBP).

Here’s a basic description of API (REST) provided by NBP:

Service reply is returned in the JSON or XML format, depending on client requirements. The reply format may be indicated in two ways – with an query parameter ?format or with a HTTP Accept header:

  • JSON format: Accept: application/json header or ?format=json parameter
  • XML format: Accept: application/xml header or ?format=xml parameter

If the format has not been determined, XML is returned.

Historic data are available respectively:

  • for currency exchange rates – since 2 January 2002,
  • for gold prices – since 2 January 2013.

and a single enquiry cannot cover a period longer than 93 days.

You will also find examples of how to call the API:

Queries for complete tables

Templates of enquiries about complete tables of currency exchange rates

  • Current table of exchange rates of type {table}{table}/
  • Series of latest {topCount} tables of exchange rates of type {table}{table}/last/{topCount}/
  • Exchange rate table of type {table} published today (or lack of data){table}/today/
  • Exchange rate table of type {table} published on {date} (or lack of data){table}/{date}/
  • Series of exchange rate tables of type {table} published from {startDate} to {endDate} (or lack of data){table}/{startDate}/{endDate}/

For more detailed information please refer to:

Let me explain what our scenario looks like. This should give you an idea of what components are involved.

ECC initializes interface over abap proxy and sends it to SAP PO which forwards it to NBP. The message is sent as XML and the receiver adapter converts it to HTTP request.

API returns data as JSON. Receiver adapter converts JSON to XML and sends the response to SAP PO which forwards the XML message back to ECC.

Picture 1. Applications involved

Now, let’s get to work!

Enterprise Services Repository configuration:

 1. Open ESR and add two namespaces in the Software Component of your choice:

  • http://…/currency/nbp       – for receiver objects
  • http://…/currency/sap        – for sender objects

2. Create request data type in both namespaces. The data type should have the following structure:

Picture 2.  Data type for request

3. Create two data types for response messages.

3.A. Namespace http://…/currency/nbp create data type as following:

Picture 3. Receiver side – response data type

3.B. In namespace http://…/currency/sap create data type as following:

Picture 4. Sender side – response data type

4. Create message types using data types that you have prepared in previous step. You should create 4 message types:

  • MT for request in sender namespace (http://…/currency/sap)
  • MT for request in receiver namespace  (http://…/currency/nbp)
  • MT for response in sender namespace
  • MT for response in receiver namespace

5. Create two Service Interface objects. One in receiver namespace and the other one in sender namespace. Use message types prepared in step 4.

6. Create message mappings. In my case they have been created in receiver namespace but you can create separate Software Component for them or add them to sender namespace as well – it’s up to you.

Picture 5. Request mapping
Picture 6. Response mapping

7. Create operation mapping object using Service interfaces created in step 5 and both mappings created in step 6.

Picture 7. Operation mapping

In the end you should end up with the following object structure:

Picture 8. Final ESR objects structure

Integration Directory configuration:

8.  Create ProxyOut sender communication channel. Since this is typical channel usually already available in your system, I will not cover how to create one in this tutorial.

9. Create receiver communication channel using REST adapter.

9.A. Leave General tab as it is.

Picture 9. Receiver CC – General

9.B. In REST URL what we need to achieve is to map the Date parameter into URL string so the service replies with expected data.

Fill in URL Pattern field with below address. Make sure that the parameter Date is in {} brackets.{Date}

Then, configure other parameters as presented in below screenshot. Provide source value as XPath Expression, name of the element and XPath to this element in your request message.

Picture 10. Receiver CC – Rest URL

9.C. In REST Operation tab make sure that you select values as presented below.

Picture 11. Receiver CC – REST Operation

9.D. In Data Format tab make sure that you set following parameters:

  • Request Format / Data Format: XML
  • Response Format / Data Format: JSON
  • Response Format / Character Set: Manual Value
  • Response Format / Set Name: UTF-8

Then select 3 following parameters:

  • Convert to XML
  • Log JSON message
  • Add Wrapper Element
Picture 12. Receiver CC – Data Format

9.E. Leave another 4 tabs – Operation Rules, Response Determination, HTTP Headers and Error Handling – untouched, as they are.

10. Create integrated configuration with elements that you have previously created.


Finally, we are ready to test the interface. Below screens have been made in SPROXY transaction:

Picture 13. Example of a request to NBP API


Thank you! 🙂

Edit 31.08.2017
This post is also available on

About maciejbialek

Hello! I'm passionate, certified ABAP developer and SAP Consultant with many years of hands-on experience gained across several projects in Telco and Energy & Utilities industries. I've worked as Integration Architect, PI and ABAP Developer as well as BPC (NW) Consultant for local and international clients.

Leave a Reply