Skip to Content
Author's profile photo Ivo Kulms

PI REST Adapter – Consuming synchronous RESTful service

This blog is part of a collection of blog entries that shows architectural concepts and configuration of the SAP PI REST Adapter. We also added some sample scenarios to make it easier for you to understand how your scenario can be implemented using the PI REST Adapter.

If you haven’t done so far, best is to start with the very first blog PI Rest Adapter – Don’t be afraid within the blog series covering the concepts of the REST adapter. A complete list of all blog entries can be accessed from here PI REST Adapter – Blog Overview.

The current blog shows you along a sample scenario how to consume a synchronous RESTful service. In the example, the target URL is set dynamically by using variables.

Scenario

We would like to determine geographic coordinates such as latitude and longitude based on a given address. This conversion is called geocoding. Here, we use Google’s Geocoding API in the following format:

http://maps.googleapis.com/maps/api/geocode/json?address=<given_address>&sensor=false


The given address is set dynamically, the output format is JSON, and the sensor parameter equals false indicates that my application does not use a sensor to determine the location.

The address data type of my outbound interface simply contains street, city, country, region, and zip code. The particular address elements are used to dynamically set the address in the URL of the RESTful service call.

00 Data Type.png

In the SAP Process Integration Designer perspective of the NetWeaver Developer Studio (NWDS), I have defined an Integration Flow with a SOAP sender channel and a REST receiver adapter, i.e., we expose the RESTful service as a SOAP web service. The format of the incoming request message is XML. The response from the Goecoding API is JSON which is converted to XML and passed back to the SOAP sender.

01 Integration Flow.png

In the following I will focus on the configuration of the receiver adapter of type REST.

Configuring the REST receiver channel

On the Integration Flow double click on the receiver channel, and switch to tab REST URL below the Adapter-Specific settings. Enter the URL Pattern as follows using variables for street, city, country, and the sensor:

http://maps.googleapis.com/maps/api/geocode/json?address={street_par}+{city_par}+{country_par}&sensor={boolean}


The address variables street_par, city_par, and country_par are replaced by the respective values in the request XML message. For each address part, I use an xpath expression to parse and read the respective values from the XML message. The boolean variable is replaced by the static value false.

02 REST URL.png

Switch to tab REST Operation. Here, I have set the http operation of my RESTful service equals GET.

03 REST Operation.png

Finally, we need to define the format of the messages of the RESTful service. Switch to tab Data Format. Though I have maintained the format of the request message, the settings for the input message are actually superfluous since we do not provide any payload anyway. All information of the request is provided in the URL as seen above. However, entering the request format in the channel doesn’t harm.

The format of the response is expected to be in JSON, so I choose JSON as data format. Furthermore I need to convert the JSON to XML and hence select the Convert to XML check box.

04 data Format.png

Running the scenario

For testing the scenario, I used soapui. In the figure below you see that I have entered an address as request in XML format. The response contains the geographic coordinates of the given address.

05 SOAP UI.png

I hope this blog was helpful to understand the consumption of RESTful services using the SAP PI REST adapter. If you like to learn more, check out the other blogs in the series, accessible from the main blog PI REST Adapter – Blog Overview.

Assigned tags

      49 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Ivo,

      Can you please clarify my query?In Advantco REST adapter,if want to provide the username and password for the URL, there we have "Enable Custom Request HTTP Headers".

      But in PO REST adapter, where to configure these details.

      I have tried using "Pattern Variable Replacement".But when executing, these details are not considered and it is displaying "401 unauhorised2 error.

      Please let me know if any inputs for my query.

      Thanks,

      Leela

      Author's profile photo Alexander Bundschuh
      Alexander Bundschuh

      Hi Leela,

      let me reply to you on behalf of Ivo since I guess that he went into xmas break already.

      Support for custom request http headers in the REST receiver channel is planned to be shipped with the next SP, i.e., 7.4 SP10, around March 2015, see also a rough roadmap in my blog

      http://scn.sap.com/community/process-orchestration/blog/2014/11/24/new-adapter-in-sap-process-integration-for-consumption-and-provisioning-of-rest-based-services

      Alex

      Author's profile photo Former Member
      Former Member

      Hi Alex,

      I want to add two lines into http headers as you see below. I understand that you said, there will be no possibility of it until March 2015. Am I right?

      Thanks,

      /wp-content/uploads/2015/01/picture_622939.png

      Author's profile photo Alexander Bundschuh
      Alexander Bundschuh

      Hi,

      right, custom http headers is planned for 7.31 SP15 which is planned to be shipped in March this year. The sample that you have shown in your screenshot should be supported.

      Alex

      Author's profile photo Jan Noorland
      Jan Noorland

      Hi Alex,

      I have a requirement to set Cross Origin http headers in the REST adapter. These have to be returned to the calling web app.

      Is this supported too with the coming SP?

      Thanks,

      Jan

      Author's profile photo Ivo Kulms
      Ivo Kulms
      Blog Post Author

      CORS support together wil anonymous access will be shipped with NW731 SP17.

      Regards,

      ivo

      Author's profile photo Former Member
      Former Member

      Hi,

      I developed scenario based this blog, but I am getting below error:

      Test.jpg

      This is the response JSON format:

      Test1.jpg

      Based on it I had created Response Data type.

      /wp-content/uploads/2015/01/test2_634640.jpg

      Please help me out in creating Data type for response.

      If structure is wrong.

      Author's profile photo Former Member
      Former Member

      You can just create response MD with one filed (simple type in string). And no need to maintain OP, then all response payload will be presented

      Author's profile photo Former Member
      Former Member

      Found a solution for your response issue Nani G? We are facing the same issue.

      Author's profile photo Former Member
      Former Member

      Hello Nani G,

      have you found a solution for your problem? I get the same error while processing the response message.

      Alexander Bundschuh

      Ivo Kulms

      Are there any possibilities to view more processing steps? We can not view the payload of the response message.

      Best regards2015-07-28 16_45_43-Message Monitor - SAP NetWeaver Administrator.png2015-07-28 16_46_09-Message Editor - SAP NetWeaver Administrator.png

      Author's profile photo Alexander Bundschuh
      Alexander Bundschuh

      Hi Volha,

      the response is displayed as separate entry in the list of messages in message monitor with sender of response equals receiver of request message and receiver equals sender of request message

      Alex

      Author's profile photo Former Member
      Former Member

      Hello Volha,

      Did you find the solution for your problem? We are also facing the same. Any help please

      Author's profile photo Former Member
      Former Member

      Hi Nani,

      your challenge is that google's result comes without any namespaces inside the xml. (You can see in the soapUI screenshot above. Or send the ws request directly via browser.) The DT of your result message is manually created. So it uses namespaces by default. In consequence your mapping does not find the root element (as it expects it with NS) => error "cannot create target element".

      Solution: use an external definition for your result message.

      We managed it that way.

      "Dirty" way: use XSLT to add the missing NS

      BR

      Björn

      Author's profile photo Javier Alcubilla Alcala
      Javier Alcubilla Alcala

      Hi all

      Could you provide all the design objects?

      I have some doubts about the response objects  (mappings, types...)

      Thanks in advance

      Author's profile photo Mauricio Antonio Garcia Hurtado
      Mauricio Antonio Garcia Hurtado

      This is frustating. They do not include a complete example with all the steps. Please do things well, illustrating step by step with the NWDS screens.

      Author's profile photo Bhavesh Kantilal
      Bhavesh Kantilal

      Hello, I am trying to use the above scenario and the same fails when the REST Adapter makes the call to Google API.

      The error we get is : HTTP GET call to http://maps.googleapis.com/maps/api/geocode/xml?address=XYZ+ABC+DEF+Bangalore&amp;sensor=false not successful. HTTP/1.0 400 Bad Request

      The reason for the error is because the REST Adapter seems to make the "&" as "& amp ;" [without spaces] in the HTTP URL Is this a bug on the SP2 version that we are on?


      Regards,

      Bhavesh

      Author's profile photo Bhavesh Kantilal
      Bhavesh Kantilal

      My bad, I had made some mistakes in the way I had passed the actual request. Missed adding a comma between the Address values.. Thanks!

      Author's profile photo NarayanaSwamy Mariyala
      NarayanaSwamy Mariyala

      Hi Ivo,

      I am planning to fetch the documents from the portal, is it possible with REST Adapter?

      Author's profile photo Ivo Kulms
      Ivo Kulms
      Blog Post Author

      I never tried this myself and I am not familiar with the REST Api , so I cannot really say.

      Have you tried it yourself and ran into issues?

      Regards,

      Ivo

      Author's profile photo Martín Piattini Velthuis
      Martín Piattini Velthuis

      Thanks for the post, very usefull.

      I developed an interface follow this post and works fine.!

      One issue I have in a new interface,

      In the REST URL I need to construct a URL pattern that have more than 10 variables.

      When I use the "pattern variable replacement" I have only 10 entries...

      How can I add more variables...?

      Thanks

      Regards

      Martin

      Author's profile photo Ivo Kulms
      Ivo Kulms
      Blog Post Author

      Hi Martin,

      when you enable the last variable, a table will become visible where you can enter more variables. Please refer to the documentation for the specific values to put in there for the various settings.

      Regards,

      ivo

      Author's profile photo Martín Piattini Velthuis
      Martín Piattini Velthuis

      Ivo,

      Thanks for the answer.

      I see the table at the end of the ten variable but I have problem with fill this.

      I follow the help documentation at,

      Configuring the Receiver REST Adapter - Advanced Adapter Engine - SAP Library

      But unsuccessfull.

      My URL is like this:

      http:..../SAP_WebDrone/ConsultasCAE?CUIT={CUIT}&CAI={CAI}&DD={DD}&MM={MM}&AA={AA}&T_COMP={T_COMP}&PV_TA={PV_TA}&PV_NOR={PV_NOR}&DOC_T={DOC_T}&DOC_NRO={DOC_NRO}&IMPORTE={IMPORTE}

      For the first ten varibles for example put (first variable):

      Pattern variable replacement:

      - Value source: "XPath Expression"

      - Pattern element name: CUIT

      - XPath expression: //CUIT

      And work ok.

      For the 11th variable I fill the table:

      Additional Pattern elements:

      - Variable: IMPORTE

      - Type: XPath

      - Expression: //IMPORTE ( but error) try with /ConsultasAFIP/IMPORTE (but error)

      Error is: "Returning to application. Exception: com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.aii.adapter.rest.ejb.receiver.PlaceholderMissingException: URL placeholder IMPORTE is not configured, or has an empty value"

      Like it not recognise the variable...

      Any suggestions?

      Thanks

      Regards

      Martin

      Author's profile photo Ivo Kulms
      Ivo Kulms
      Blog Post Author

      I am afraid, but all you can do is sit and wait 😀

      We have recently fixed this issue and the fix will be shipped as part of the (weekly) patch cycle. (refer to SAP Note 2186319 - is it not released yet)

      Sorry for the inconvenience,

      ivo

      Author's profile photo Martín Piattini Velthuis
      Martín Piattini Velthuis

      Ok

      Thanks

      😥 jejeje

      Regards

      Martin

      Author's profile photo Former Member
      Former Member

      Hi everyone,

      Thank you so much, all blogs are very interesting and helpful.

      Currently, I am facing some issues with a Receiver Rest Adapter in SAP PI 7.4 SP 10 using OAuth Authentication with SAML Bearer Assertion. The Web service which I want to consume is a Web Service of Salesforce Company. I have already been reading documentation about Salesforce Web services as well as Rest Adapter, but I have not could do it.  Do you have any sample scenario about that?

      Alexander Bundschuh Ivo Kulms Abdullah Azzouni Blog It Forward - Simona Lincheva

      Author's profile photo Former Member
      Former Member

      Hi Ivo Kulms

      Can you please tell me how to create the inbound interface for receiver REST adapter?

      Do we get any XSD or WSDL for REST API ??

      Or we create the inbound interface with same structure that we have used in the SOAP sender side?

      Thanks,

      Indrajit

      Author's profile photo Former Member
      Former Member

      Hi,

      Thank you so much for the post.

      I am trying to use the above scenario and I have problems with GET parameters. I configured a receiver REST channel. I use this URL pattern: http://<domain_name>/api/transactions_logs?start_date={start_date_par}&end_date={end_date_par}&paginate={boolean} and I configured all elements start_date_par, end_date_par and boolean.

      It seems like PI call only uses URL http://<domain_name>/api/transactions_logs without any parameter.

      When I try testing the URL from Chrome rest client, the target application gets a perfect hit.

      I tried hardcoding all the variables putting in the URL pattern the value

      http://<domain_name>/api/transactions_logs?start_date=2015-09-10T09:00:00&end_date=2015-09-10T09:00:00&paginate=false with same result.

      Can you help me?

      Can you tellme if there are any monitor where I can check URL and message used for PI?

      Any help will be apreciated

      Author's profile photo Ashutosh R
      Ashutosh R

      Hi,

      Could you advice some inputs on     " Rest Receiver Adapter : extracting synchronous Response header data" .

      i tried to get from scn, but no path forward to proceed..?

      Regards,

      Ashu

      Author's profile photo Former Member
      Former Member

      Hi Ivo/Alex,

      I am working on SOAP(XI) to REST synchronous scenario. I am facing with JSON to XML conversion while executing the scenario.

      PI is sending the request to REST URL in JSON format. For multiple record PI channel is generating JSON in correct format but when we are sending request with single record PI channel is not generating “[ “ (square bracket) for an array field (Items) as required in JSON format.

      Below is the required JSON format:

      {

      "A": "abc",

      "B": "def",

      "C": TRUE,

      "Items": [

            

              { "T": "123ASD", "c": false }

          ]

      }

      Below is the JSON generated by PI:

      {

      "A": "abc",

      "B": "def",

      "C": TRUE,

      "Items":             

              { "T": "123ASD", "c": false }

      }

      Any suggestion on this issue?

      Thanks & Regards,

      Nida Fatima

      Author's profile photo Alexander Bundschuh
      Alexander Bundschuh

      Hi Nida,

      will be supported with next SP shipment 7.31 SP17 / 7.4 SP13, planned to be shipped in November

      Alex

      Author's profile photo Former Member
      Former Member

      Hi,

      I am facing the following challenge while configuring Receiver REST Adapter. The API I am trying to call requires a content MD5-checksum in the HTTP header

      2015-10-21 10_31_42-https___mws.amazonservices.de_scratchpad_index.html.png

      The content-MD5 is not a part of the URL, so it is not possible to set the parameter via Adapter Specific Attributes.

      Thanks & Regards

      Volha

      Author's profile photo Former Member
      Former Member

      How did you create the data type of the response of google? I miss this step.

      Author's profile photo Alexander Bundschuh
      Alexander Bundschuh

      Hi Umberto,

      I haven't done any mapping of the response, so no need to define a data type, otherwise you simply have to create the data type in ESR based on a sample XML response

      Alex

      Author's profile photo Former Member
      Former Member

      Hi Alexander,

      I have known the steps of how you created the scenario,  how did you not use maping in response.

      Author's profile photo Jocelyn Dart
      Jocelyn Dart

      Hi Umberto, this post is nearly a year old. If you have a question, please post a discussion in the SAP Process Orchestration forum, and add a link to the original blog.

      Rgds,

      Jocelyn, a SCN Moderator

      Author's profile photo Mauricio Antonio Garcia Hurtado
      Mauricio Antonio Garcia Hurtado

      According with Umberto, this is frustrating. You do not include a complete example with all the steps. Please do things well, illustrating step by step with the NWDS screens.

      Author's profile photo Juan Vasquez
      Juan Vasquez

      I am getting the same issue

      can you please help me with this

      <![CDATA[

      com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.aii.adapter.rest.ejb.common.exception.HttpCallException: HTTP GET call to http://maps.googleapis.com/maps/api/geocode/json?address=5th Avenue+New York+USA&sensor=false not successful. HTTP/1.0 400 Bad Request

        at com.sap.aii.adapter.soap.web.SOAPHandler.processSOAPtoXMB(SOAPHandler.java:772)

        at com.sap.aii.adapter.soap.web.MessageServlet.doPost(MessageServlet.java:530)

      2016-01-07 16_49_07-SoapUI 4.6.2.png

      this is my channel configuration

      2016-01-07 16_45_32-Configuration_ Integration Builder (coibmpodaix01_POD_00).png

      2016-01-07 16_46_31-Configuration_ Integration Builder (coibmpodaix01_POD_00).png

      2016-01-07 16_46_54-Configuration_ Integration Builder (coibmpodaix01_POD_00).png

      Thanks a lot for your help

      Author's profile photo Avinash Ayanala
      Avinash Ayanala

      Hello Team,

      Thank you very much for this wonderful blog. I have some query from my side.

      i am getting the error as given below

      http://maps.googleapis.com/maps/api/geocode/json?address=5th Avenue+New York+USA&sensor=false not successful. HTTP/1.0 400 Bad Request

      but the url is successfully working in web browser but getting reply as http/1.0 400 bad request.

      and i am using the below XML structure to send the request

      <?xml version="1.0" encoding="UTF-8"?>

      <ns0:address xmlns:ns0="XYZ">

         <street/>

         <city/>

         <country/>

         <region/>

         <zip/>

      </ns0:address>

      please suggest if any of the above details are wrong and is there any necessary to upgrade the patch level ?

      regards,

      Avinash.

      Author's profile photo Ivo Kulms
      Ivo Kulms
      Blog Post Author

      Hi Avinash,

      please check the space between "5th" and "Avenue.

      For convienience Web browsers do replace the invalid space automatically.

      Best Regards,

      Ivo

      Author's profile photo Avinash Ayanala
      Avinash Ayanala

      Hi Kulms,

      I have tried it but still no luck getting the same error.

      Regards,

      Avinash

      Author's profile photo Juan Vasquez
      Juan Vasquez

      Hello Avinash

      Plese see this, i had the same Issue

      Issue Consuming synchronous RESTful service

      Author's profile photo Former Member
      Former Member

      I have configured a scenario with a REST receiver for consuming a REST Service. My URL looks like that:

      http://server:port/service?para1={para1}&para2={para2}

      The para1 and para2 are in my request payload. The problem is that these parameters are optional. It is possible that they have no value. And the REST service allows calls like this:

      http://server:port/service?para1=&para2=&value2

      But I get always an error when I try to call the service via the REST receiver with an empty parameter.

      "MP: exception caught with cause com.sap.aii.adapter.rest.ejb.receiver.PlaceholderMissingException: URL placeholder para1 is not configured, or has an empty value"

      In my real scenario I have more than 2 parameters and one or more of them are always empty. Is there a solution for this problem? Otherwise I can't use this for my purpose or I have to find a workaround (combine all parameter in one)

      Author's profile photo Alex Wiebe
      Alex Wiebe

      Hmmm... I'm not quite there yet, but I will require optional parameters as well in my use case. Have you resolved this issue?

      Author's profile photo Sung-Yen Yang
      Sung-Yen Yang

      Hi Alex,

      I was trying to achieve the same thing like Gil, but in the end figured out that it's impossible to leave any parameter value empty. Even I combined all parameters in one in my Java mapping program. "&" this kind of symbol was encoded by PO, and result went error.
       

      Author's profile photo Former Member
      Former Member

      Dear All,

      I am new to SAP PI but I developed this scenario. During  testing from SOAP UI I am getting the connection time out error  with message ""/wp-content/uploads/2016/08/err1_1016140.png

      Following error message log in Message monitoring

      error2.PNG

      Author's profile photo Arthur Silva
      Arthur Silva

      Hello,

      Regarding first image. Do you know where do I get the latest version of NWDS with SAP PI perspective inside?    

      I have been working with SAP PI 7.3 for the last few years, is the scenario configuration the same and it only differs by the Adapter type in the ES Builder?

      Kindly regards,

      Arthur Silva

      Author's profile photo Mauricio Antonio Garcia Hurtado
      Mauricio Antonio Garcia Hurtado

       

      Again the blogs of sap with incomplete examples, poorly illustrated, without detailed step by step. When I look for information on these blogs, the least I expect is the complete and detailed information
      Author's profile photo Krishna Sharma Hari
      Krishna Sharma Hari

      Hi Ivo / Alexander,

       

      Thanks for the blog series. This has really helped me to be un-afraid of the REST adapter as suggested 🙂

       

      We are currently on PI 7.4 and I have an option to define Custom HTTP Headers in the Receiver REST Adapter.

      However, I face a challenge:

      The HTTP Headers that i need to pass are the username and password.

      The configuration successfully works when i provide them and the REST call is completed.

      However, the issue is that the Password is visible (unmasked) in the Channel as well as in the message audit log (RESTOUT_HTTP_HEADER - pl see screenshots below)

       

       

      Is there any way to mask the password or provide the Authentication Header in another way ?

       

      Regards,

      Krish

       

      Author's profile photo Ramprasad Medindrao
      Ramprasad Medindrao

      Hello Experts,

      I do have strange issue in Asynchronous Rest sender adapter for integer json type.

      When i am posting data using postman for one integer field, if its length is 4 then the request is successful to SAP PO, but if more than 4 digits we are getting 404 error.

      Data type for that field is maintained as integer and 0.unbounder occurances in SAP PO.

      Can some one help on this scenario please as we are using SAP PO 7.5 single stacks SP09.