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.
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.
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.
Switch to tab REST Operation. Here, I have set the http operation of my RESTful service equals GET.
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.
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.
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.
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
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
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,
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
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
CORS support together wil anonymous access will be shipped with NW731 SP17.
Regards,
ivo
Hi,
I developed scenario based this blog, but I am getting below error:
This is the response JSON format:
Based on it I had created Response Data type.
Please help me out in creating Data type for response.
If structure is wrong.
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
Found a solution for your response issue Nani G? We are facing the same issue.
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 regards

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
Hello Volha,
Did you find the solution for your problem? We are also facing the same. Any help please
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
Hi all
Could you provide all the design objects?
I have some doubts about the response objects (mappings, types...)
Thanks in advance
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.
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&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
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!
Hi Ivo,
I am planning to fetch the documents from the portal, is it possible with REST Adapter?
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
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
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
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
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
Ok
Thanks
😥 jejeje
Regards
Martin
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
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
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
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
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
Hi Nida,
will be supported with next SP shipment 7.31 SP17 / 7.4 SP13, planned to be shipped in November
Alex
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
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
How did you create the data type of the response of google? I miss this step.
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
Hi Alexander,
I have known the steps of how you created the scenario, how did you not use maping in response.
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
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.
I am getting the same issue
can you please help me with this
<
Following error message log in Message monitoring
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
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
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
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.