Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Lets assume that we have business requirement that -we need to get the bearer token from the WEBSEVER and call the REST API to get the PO details and split the data and gather in target output as we require. This blog may help to answer query- why SAP not included creating DT, MT in SAP CPI as we do in traditional SAP PI system.

this blog explains you complete step by step procedure for implementation for  REST API to SFTP file creation with Content Modifier, Split and Gather .


REST API [JSON] --> SAP CPI [Transformation With Split and Gather] -->Create a output file in desired our own output format.

First you need to understand given REST API in POSTMAN tool. In most of the cases for accessing REST API data first we need to call Bearer token API and pass the Bearer token with REST API URL for fetching the business/purchase order details.

For getting the Bearer token we need to write the groovy script as below when the token parameters are maintained in body along with Content modifier header parameters as per POSTMAN header and body parameter settings.

All HTTPs REST API will have valid certificates - you need to download the certificate and deploy in SAP CPI in Keystore.

create a groovy script step in CPI - use this below code for calling Bearer token and ensure that you have maintained clientid, client_secret,and username and password in security material keys.

import java.util.HashMap;

def Message processData(Message message) {

//Credentials // the same credentials needs to update in secure material.
def secret = "Username";
def user = "Password";

//service to get the credentials
def service = ITApiFactory.getApi(SecureStoreService.class, null);

//get secret credential
def secretCred = service.getUserCredential(secret);
if (secretCred == null){
throw new IllegalStateException("No credential found for alias " + secret);

//get user credential
def userCred = service.getUserCredential(user);
if (userCred == null){
throw new IllegalStateException("No credential found for alias " + user);

//HTTP Parameters value
String grant_type = "password";
String client_id = secretCred.getUsername();
String client_secret = new String(secretCred.getPassword());
String username = userCred.getUsername();
String password = new String(userCred.getPassword());

def query = "";
query = query + "grant_type=" + grant_type + "&";
query = query + "client_id=" + client_id + "&";
query = query + "client_secret=" + client_secret + "&";
query = query + "username=" + username + "&";
query = query + "password=" + password;


return message;

we need to get the similar bearer token in SAP CPI with groovy script.

i am passing the Bearer token for calling PO REST API as below.

the REST API metadata will be our source structure like we create in DT and MT in SAP PI and for target datatype and message type we can define in Content Modifier  - probably this could be the reason in SAP CPI cloud we do not have option for creating creating DT, MT in SAP CPI.

the default output format for all REST API - will be JSON Format - Lets us use HTTP adapter with request and reply step to read the data. when we use HTTP adapter it just reads the data it won't fetch the metadata structure and schema definition files in resources. Once we get the JSON format in CPI convert JSON TO XML and with help of XML file we can create XSD schema definition files with help of 



In the above IFLOW - we are getting the data and we are converting the JSON into XML.

in spliter x path expression taken as // Lines as multiple records in Purchase order which you have seen in POSTMAN screen.


Message header parameters helps with playing your incoming XML payload in IFLOW as above.

if you see body parameters ID, PaymentTerms, Material - is the output schema structure as we do in creating DT, MT in SAP PI. whatever the names you will define in xml <tags> will be your target structure - this could be the reason in SAP CPI - you can't see creating DT, MT for source or target structure.



gather step and Deploy the IFLOW - to check output message and process the same to SFTP server. if your SFTP server is on-premise then do not forget that you need to maintain the SFTP server details in SAP Cloud connector with TCP port connection.


its complete output in XML in desired format as we defined in Content modifier Body Parameter. Check the input with POSTMAN first screenshot and output in above screenshot for more clarification.


hope this helps in your project work!!


Best Regards,

Krushi Nenavath.
Labels in this area