Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
ivo_kulms
Associate
Associate
81,998

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.

49 Comments
Former Member
0 Kudos

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

alex_bundschuh
Product and Topic Expert
Product and Topic Expert
0 Kudos

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-integr...

Alex

Former Member
0 Kudos

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,

alex_bundschuh
Product and Topic Expert
Product and Topic Expert
0 Kudos

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 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

javier_alcubilla
Contributor

Hi all

Could you provide all the design objects?

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

Thanks in advance

bhavesh_kantilal
Active Contributor
0 Kudos

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

bhavesh_kantilal
Active Contributor
0 Kudos

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!

0 Kudos

Hi Ivo,

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

0 Kudos

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

ivo_kulms
Associate
Associate
0 Kudos

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_kulms
Associate
Associate
0 Kudos

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

ivo_kulms
Associate
Associate
0 Kudos

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

Regards,

ivo

0 Kudos

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

ivo_kulms
Associate
Associate
0 Kudos

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

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 Kudos

Ok

Thanks

:cry: jejeje

Regards

Martin

Former Member
0 Kudos

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

alex_bundschuh
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

former_member192079
Participant
0 Kudos

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

Former Member
0 Kudos

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

alex_bundschuh
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Nida,

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

Alex

Former Member
0 Kudos

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

Former Member
0 Kudos

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

alex_bundschuh
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

Former Member
0 Kudos

Hi Alexander,

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

Jocelyn_Dart
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

juan_vasquez2
Active Participant
0 Kudos

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)

this is my channel configuration

Thanks a lot for your help

avinash_ayanala
Participant
0 Kudos

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.

ivo_kulms
Associate
Associate
0 Kudos

Hi Avinash,

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

For convienience Web browsers do replace the invalid space automatically.

Best Regards,

Ivo

avinash_ayanala
Participant
0 Kudos

Hi Kulms,

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

Regards,

Avinash

juan_vasquez2
Active Participant

Hello Avinash

Plese see this, i had the same Issue

Issue Consuming synchronous RESTful service

Former Member
0 Kudos

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)

Former Member
0 Kudos

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 ""

Following error message log in Message monitoring

arthursilva
Active Participant
0 Kudos

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

alex_wiebe
Participant
0 Kudos
Hmmm... I'm not quite there yet, but I will require optional parameters as well in my use case. Have you resolved this issue?
Former Member
0 Kudos
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.
 
Former Member
0 Kudos
Hello Volha,

Did you find the solution for your problem? We are also facing the same. Any help please
0 Kudos
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.
0 Kudos
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.
 
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
former_member211899
Participant
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

 
ram2linkin
Explorer
0 Kudos
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.