Skip to Content
Author's profile photo Luke Allen

REST Sender Adapter GET and POST Examples

Thought I would share some notes I took when testing REST adapter functionality, with thanks to the following blog for getting me started https://blogs.sap.com/2014/12/18/pi-rest-adapter-blog-overview/.  The example that follow are based on a REST sender request calling an RFC in ECC.  Only the steps relevant to using the REST adapter are shown.

SENDER ADAPTER – GET

Data is send in HTTP header therefore no payload is submitted

ESR

Could not find any examples on how to do this so there may be better ways than my methodology – create a dummy message type for the request message

For the request message mapping populate fields with constants where required

For fields where the data will be passed in from the URL or via parameters create function to read the data from the dynamic attributes of the message

public String getASMA(String attribute, String namespace, Container container) throws StreamTransformationException{
Map map = container.getTransformationParameters();
DynamicConfiguration conf = (DynamicConfiguration)map.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create( namespace, attribute);
String value = conf.get(key);
return value;
}

Use UDF in mapping

Where ‘attribute’ field in UDF (constant ‘id’ in this example) = Name of Dynamic attribute in communication channel (see further down for details on setting this up)

And ‘namespace’ field in UDF is set to: http://sap.com/xi/XI/System/REST

ID

Configure Sender REST adapter

Does not matter what the input message format is since no payload sent with GET requests
Output message can be XML or JSON

On Channel Selection tab tick specify endpoint and enter name of resource the client will call
Can use format {name}/{name2}…. As required

On REST Resources tab set URL Pattern to ‘Custom Pattern’ and then specify what attributes will be fed from the URL, attributes put in curly brackets.  Next populate the XI Dynamic attribute settings, this dictates what get set in the dynamic attributes of the message and can then be read in message mapping.  In below example an attribute of ‘id’ will be created with a value as passed in the URL {cust_no} place holder.

On Operation Determination tab set pointer to the interface to call (assume needs this since no payload was passed?).  In the below example Operation and Namespace are set to the Name and namespace of the request Message Type respectively.

SOAP UI

Method = ‘GET’
Endpoint = ‘http://{host}:{port}/RESTAdapter’
Resource = Endpoint value specified above in communication channel plus the URL pattern

                                                                                 

So in the above example data is retrieved for customer 010

To run for a different customer just change the last value

To Run using a Parameter instead:

Change adapter as below

SOAP UI call then looks like

SENDER ADAPTER – POST XML

Data is sent in HTTP body and receiver as payload in PI

On Channel Selection tab tick specify endpoint and enter name of resource the client will call
Can use format {name}/{name2}…. As required

In SOAPUI set Method to ‘POST’ and endpoint to ‘http://{host}:{port}/RESTAdapter’ and Resource to the Endpoint value specified above in communication channel.  Nb I used the BAPI data format for the sender and receiver interfaces.

SENDER ADAPTER – POST JSON

Set input data format as JSON and tick ‘Convert to XML’ and ‘Add Wrapper Element’
Enter Element Name/Namespace as per Root node of expected message (Request message)

Above settings will convert JSON to PI required format

Change output data format to JSON and tick ‘Convert XML payload to JSON’
(could leave output as xml if required)

On Channel Selection tab tick specify endpoint and enter name of resource the client will call

In SOAPUI set Method to ‘POST’ and endpoint to ‘http://{host}:{port}/RESTAdapter’ and Resource to the Endpoint value specified above in communication channel

Set Media Type to ‘application/json’ and enter json for required fields in PI sender service interface is expecting

Assigned tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jimmy Moreno
      Jimmy Moreno

      Hi Luke.

      Excellent step by step. I created a REST sender adapter with GET method, if I can more parameters the REST RESOURCES' configuration will be like this?

      And message mapping definition request with UDF, question with every field can I do this?.

      Last question, In ASMA code I have to capture every field?

      Thanks in advance.

       

      Jimmy.

      Author's profile photo Glen Anthony
      Glen Anthony

      Hi Jimmy,

      May i ask, were you able to create more than 1 import parameter for your RFC?

      I'm struggling to do this now!

      Author's profile photo Rajesh PS
      Rajesh PS

      Hello

       

      Your thought on this.

      https://answers.sap.com/questions/12879150/how-to-send-http-body-parameters-in-sap-po-75.html

      Author's profile photo Monica Duraipandi
      Monica Duraipandi

      Hi All,

      I was able to achieve the multi-Dynamic attributes .Kindly find the REST OPERATION for reference

      Kindly include ASMA(function for all dynamic attributes)

      Author's profile photo Siva Bala
      Siva Bala

      Hello Gurus,

      I have a requirement to configure a SENDER REST channel and need help with. It is not clear as to which method I have to use. What is the endpoint URL here? In my case I'm thinking of enabling a proxy method to fetch data from the backend. I was told that the request will be in JSON format with one field input value (which is phone number) and I have to pass the same to CRM to fetch email id of the account that matched the phone number. Any step by step help would be greatly appreciated.

      Thanks,

      Siva