Skip to Content
Technical Articles

End to End Integration Between SAP Cloud API, Cloud CPI with XS ODATA services + OAUTH Bearer Token Integration with External Cloud Applications.

As technologies are changing in SAP Integration front from SAP PI/PO to SAP Cloud API and CPI and more customer is looking for Digital transformations- thought to share the new integration approach between SAP Cloud API and SAP cloud CPI.

Most of us worked with IDOC, PROXY, RFC, BAPI, File approach  integration – with SAP PI/PO – however SAP CPI is offering Integration approach with ODATA services.

There is a  new integration approach how we can achieve SAP HANA Standard Calculation views and writing XS ODATA services on top of SAP provided standard 1000+ calculation views and consume the XS ODATA Service into SAP Cloud API via SAP Cloud connector. This will reduce estimation of efforts and can save lot of developers time. And also once we setup SAP Cloud connector and connectivity setup between ON PREMISE systems and SAP Cloud API and CPI – No need to approach Network team for enabling the firewall -IP NAT and connecting with any external network systems – This definitely saves lot of time and no need to work with network team as we can see the complete traffic in SAP cloud connector trace file.

the complete flow will be as below.

SAP ECC/S4/HANA ON PREMISE –> SAP Cloud Connector –> SAP Cloud API –> SAP CPI –> any external Cloud Application Integration.

Customer who have chosen SAP HANA as DATABASE -SAP is offering [1000+ with all business processes ] SAP standard Calculation Views on top of it we can add small piece of code for building XS ODATA services as below.

 

Chose the SAP HANA standard calculation view as per the business requirement and build the XS ODATA service as below.

 

service {

“_SYS_BIC”.”sap.hba.ecc/Vendor” as “et_Vendor” keys generate local “Vendor”;

}

 

As there are many blogs on how we can ref for building XS ODATA Service- now bring th

TEST –HANA  in any browser – it will give the result as below.

http://IP Address:8005/Vendor/Vendor.xsodata/et_Vendor?$top=10

Just for example i have given the XS ODATA Code for Vendor.

Due to Data protection act by Govt -As you most of you know customer will have ECC /S4 HANA will host the server in ON PREMISE.

now its time to expose created XS ODATA service into SAP Cloud API via SAP Cloud Connector. Install SAP Cloud connector and map backend on premise systems with SAP Cloud connector. There are many SAP standard blogs can ref.

 

your XS ODATA services and ODATA services which are existing in SAP GATEWAY system and can consume in backend systems via SAP Cloud connector.

once the ODATA/XS ODATA service is available in SAP Cloud API then it will be very easy to integrate with any external cloud applications/Fiori Apps/Native Apps.

 

Now i am using XS odata service which is available in SAP Cloud API into SAP CPI.

SAP any master Vendor/Business Partner/ Material data replication between SAP ECC/ S4HANA and external any cloud application – condition are as below.

1st condition-Get the OAUTH Bearer token from external cloud application 1st REST API.

2nd Condition -pass employee id and bearer token along with header parameters -2nd REST API.

3rd condition – Get the external external ID and call 3rd REST API with bearer token for Master data Synch Between SAP On premise to External Customer cloud applications.

Lets see how we can all theree REST API’s and get OAUTH Bearer token – we should ask our partner to show how the REST API works in POSTMAN – then same we need to replicate in SAP CPI.

 

 

SAP Groovy -code for passing all BODY parameters which we have seen in postman and maintain the user id details in managed secure key store in CPI.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import com.sap.it.api.ITApiFactory;
import com.sap.it.api.securestore.SecureStoreService;
import com.sap.it.api.securestore.UserCredential;

def Message processData(Message message) {

//Credentials
def secret = “SPIGIT_Secret”;
def user = “SPIGIT_User”;

//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());

//Query
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;

message.setBody(query);

return message;
}

 

first ODATA service calls to SAP Cloud API gets the require data from backend systems as explained above and maintain the content modifier parameters and call other REST other API for getting the data from external application and update/insert through API’s.

 

lets check the Trace for complete end to end PIPELINE Steps.

 

Data is updated in external Cloud Applications – hope this blogs helps in our project work.

 

Best Regards,

Krushi Nenavath

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