Saturday, August 2, 2025

Gaurab's Blog : CPI Integration with BW/4HANA - lm_allen

Introduction

The below blog provides an overview of setting up a simple CPI integration to post data to a SAP BW/4HANA on-premise instance.  I have included an explanation of how to achieve this in both postman and SAP Cloud Integration.  I have also included references to helpful blogs you can refer to for additional details.

Set up in BW

Create DSO in BW

lm_allen_0-1754121199342.png

Ensure 'Write Interface Enabled' attribute is set.

lm_allen_1-1754121199344.png

Add fields to DSO

lm_allen_2-1754121199345.png

 

Download URL's shown on DSO

Get Structure

https://server:port/sap/bw4/v1/push/dataStores/da_maze

Get Sample Data

https://server:port/sap/bw4/v1/push/dataStores/da_maze/sampleData{?records,seed}

Send Data

https://server:port/sap/bw4/v1/push/dataStores/da_maze/dataSend{?request,datapid}

Open Request

https://server:port/sap/bw4/v1/push/dataStores/da_maze/requests

Close Request

https://server:port/sap/bw4/v1/push/dataStores/da_maze/requests/{request}/close{?error}

 

Using DSO in Postman

For Info can query DSO structure

lm_allen_3-1754121199347.png

Or see an example json payload

lm_allen_4-1754121199348.png

 

Post data in postman:

Step 1: Fetch CSRF token

Add header for x-csrf-token = fetch, set Authorization to basic Auth

lm_allen_5-1754121199349.png

Response header will contain the csrf token

lm_allen_6-1754121199350.png

Step 2: Send Data to BW

Add header x-csrf-token and set value returned by call in Step 1 (found in the response header)

lm_allen_7-1754121199351.png

Set body to message to post to BW (xml in this example)

lm_allen_8-1754121199352.png

Response back

lm_allen_9-1754121199353.png

Example JSON POST

lm_allen_10-1754121199353.png

 

Data Post example in CPI

The process below mirrors the process done previously in postman to post data to BW

lm_allen_11-1754121199354.png

 

Against the Integration flow set HTTP session

lm_allen_12-1754121199354.png

 

  1. Start Timer - Schedule set to Run Once
  2. Set Csrf token header

lm_allen_13-1754121199355.png

3. Make http call to get csrf token returned (note that in this example an on-premise BW is being called so virtual host/port have been set in cloud connector)

lm_allen_14-1754121199356.png

Make sure Headers are both passed to the call and returned

lm_allen_15-1754121199356.png

4. Handle Cookies - The initial csrf call returns an header called 'set-cookie', unfortunately the call to post the data requires an header called 'cookie'.  The groovy script converts the format and name.  More details can be found in https://help.sap.com/docs/SUPPORT_CONTENT/sci/3361897820.html?locale=en-US

import com.sap.gateway.ip.core.customdev.util.Message;

def Message processData(Message message) {

    def headers = message.getHeaders();

    def cookies = headers.get("set-cookie");

    message.setHeader("cookie", String.join("; ", cookies));

return message;

}        

5. Set content type and payload of data post

lm_allen_16-1754121199357.png

lm_allen_17-1754121199357.png

6. HTTP call to post data to BW

lm_allen_18-1754121199358.png

 

Referenced Blogs:

Integrating with BW

From <https://community.sap.com/t5/technology-blog-posts-by-sap/sap-bw-4hana-write-interface-enabled-adso-connected-to-a-3rd-party-tool/ba-p/13482277>

Example CPI to BW

https://community.sap.com/t5/technology-blog-posts-by-sap/sap-cloud-platform-integration-cpi-to-push-data-into-sap-bw-4hana/ba-p/13418310

Issues with x-csrf not working see below:

https://community.sap.com/t5/technology-blog-posts-by-members/x-csrf-token-with-on-premises-sap-system-using-http-receiver-adapter/ba-p/13533518

https://help.sap.com/docs/SUPPORT_CONTENT/sci/3361897820.html?locale=en-US

Introduction

The below blog provides an overview of setting up a simple CPI integration to post data to a SAP BW/4HANA on-premise instance.  I have included an explanation of how to achieve this in both postman and SAP Cloud Integration.  I have also included references to helpful blogs you can refer to for additional details.

Set up in BW

Create DSO in BW

lm_allen_0-1754121199342.png

Ensure 'Write Interface Enabled' attribute is set.

lm_allen_1-1754121199344.png

Add fields to DSO

lm_allen_2-1754121199345.png

 

Download URL's shown on DSO

Get Structure

https://server:port/sap/bw4/v1/push/dataStores/da_maze

Get Sample Data

https://server:port/sap/bw4/v1/push/dataStores/da_maze/sampleData{?records,seed}

Send Data

https://server:port/sap/bw4/v1/push/dataStores/da_maze/dataSend{?request,datapid}

Open Request

https://server:port/sap/bw4/v1/push/dataStores/da_maze/requests

Close Request

https://server:port/sap/bw4/v1/push/dataStores/da_maze/requests/{request}/close{?error}

 

Using DSO in Postman

For Info can query DSO structure

lm_allen_3-1754121199347.png

Or see an example json payload

lm_allen_4-1754121199348.png

 

Post data in postman:

Step 1: Fetch CSRF token

Add header for x-csrf-token = fetch, set Authorization to basic Auth

lm_allen_5-1754121199349.png

Response header will contain the csrf token

lm_allen_6-1754121199350.png

Step 2: Send Data to BW

Add header x-csrf-token and set value returned by call in Step 1 (found in the response header)

lm_allen_7-1754121199351.png

Set body to message to post to BW (xml in this example)

lm_allen_8-1754121199352.png

Response back

lm_allen_9-1754121199353.png

Example JSON POST

lm_allen_10-1754121199353.png

 

Data Post example in CPI

The process below mirrors the process done previously in postman to post data to BW

lm_allen_11-1754121199354.png

 

Against the Integration flow set HTTP session

lm_allen_12-1754121199354.png

 

  1. Start Timer - Schedule set to Run Once
  2. Set Csrf token header

lm_allen_13-1754121199355.png

3. Make http call to get csrf token returned (note that in this example an on-premise BW is being called so virtual host/port have been set in cloud connector)

lm_allen_14-1754121199356.png

Make sure Headers are both passed to the call and returned

lm_allen_15-1754121199356.png

4. Handle Cookies - The initial csrf call returns an header called 'set-cookie', unfortunately the call to post the data requires an header called 'cookie'.  The groovy script converts the format and name.  More details can be found in https://help.sap.com/docs/SUPPORT_CONTENT/sci/3361897820.html?locale=en-US

import com.sap.gateway.ip.core.customdev.util.Message;

def Message processData(Message message) {

    def headers = message.getHeaders();

    def cookies = headers.get("set-cookie");

    message.setHeader("cookie", String.join("; ", cookies));

return message;

}        

5. Set content type and payload of data post

lm_allen_16-1754121199357.png

lm_allen_17-1754121199357.png

6. HTTP call to post data to BW

lm_allen_18-1754121199358.png

 

Referenced Blogs:

Integrating with BW

From <https://community.sap.com/t5/technology-blog-posts-by-sap/sap-bw-4hana-write-interface-enabled-adso-connected-to-a-3rd-party-tool/ba-p/13482277>

Example CPI to BW

https://community.sap.com/t5/technology-blog-posts-by-sap/sap-cloud-platform-integration-cpi-to-push-data-into-sap-bw-4hana/ba-p/13418310

Issues with x-csrf not working see below:

https://community.sap.com/t5/technology-blog-posts-by-members/x-csrf-token-with-on-premises-sap-system-using-http-receiver-adapter/ba-p/13533518

https://help.sap.com/docs/SUPPORT_CONTENT/sci/3361897820.html?locale=en-US

Source: https://community.sap.com/t5/technology-blog-posts-by-members/cpi-integration-with-bw-4hana/ba-p/14170026 Date: 2025-08-02T08:11:44.000Z

No comments:

Post a Comment

CoPilot For Eclipse - The Joule Alternative

GitHub CoPilot works alongside you in the Eclipse Editor. It autogenerates code suggestions, provides correction syntax. Free version includ...