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.

To report this post you need to login first.

43 Comments

You must be Logged on to comment or reply to a post.

  1. Leela Morampudi

    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

    (0) 
    1. 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

      (0) 
  2. ESRA AKKOCA

    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

    (0) 
    1. 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

      (0) 
  3. 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

    (0) 
  4. Nani G

    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.

    (0) 
    1. Qingfeng Li

      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

      (0) 
    2. Volha Ptukha

      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

      (0) 
      1. 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

        (0) 
    3. Björn Majunke

      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

      (0) 
  5. 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

    (0) 
    1. Ivo Kulms 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

      (0) 
  6. 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

    (0) 
    1. Ivo Kulms 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

      (0) 
      1. 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

        (0) 
        1. Ivo Kulms 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

          (0) 
  7. Ochoa Marcel

    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

    (0) 
  8. Indrajit Sarkar

    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

    (0) 
  9. Jessica Villamor Gerboles

    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

    (0) 
  10. Nida Fatima

    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

    (0) 
  11. Volha Ptukha

    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

    (0) 
    1. 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

      (0) 
        1. 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

          (0) 
  12. 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

    (0) 
  13. 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.

    (0) 
    1. Ivo Kulms 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

      (0) 
  14. Gil Ritter

    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)

    (0) 
      1. 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.
         

        (0) 
  15. Shahid Ali

    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

    (0) 
  16. 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

    (0) 

Leave a Reply