Technical blog
Creating Customer in SAP S/4 HANA Public Cloud via OData

created by Midjourney

Jiri Fridrich
17. 1. 2025
Integration
Let's see how to create Business Partner as Customer in SAP S/4 HANA Public Cloud via HTTP adapter in SAP Cloud Integration.
SAP provides RESTful API (A2X), which is available at the Business Accelerator Hub.
From the environment of SAP Cloud Integration, we have actually two options - we can use OData adapter or HTTP adapter. When in decision about which one to choose, this blog can help you. I wanted to have more flexibility over the entire process and hence I will be describing the use of HTTP adapter. It requires more work, but provides you with higher level of control.
The structure of SAP S/4 APIs can be sometimes confusing, as it doesn't always follow a consistent logic. Sometimes you are referring to Business partner in the query, sometimes in the payload. Sometimes an object has its own API, sometimes you use an extension of another object's API. No worry, we will clarify this.
X-CSRF-TOKEN
The first obstacle you face using HTTP adapter is the handling of authentication against the SAP S/4. As creating a Business Partner is a POST operation, you need higher privileges then when using GET query. And that is why we need to get x-csrf-token first.
To achieve this, we need to set a request to this service:
/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner
We run this request in Request-Reply component with HTTP adapter:

HTTP method I select HEAD, as we are not sending any content, neither we are asking for data. So to minimize the exchange overhead, I think HEAD is the most economic method for this kind of call.
The asterisks in Request Headers and Response Headers ensure that the headers will be exchanged and that we will receive all the headers we need.
You may be wondering why we are calling the /A_BusinessPartner service, when we want to get the token. The reason is that we should be calling the same service which we will call to actually create the Customer later.
Right before the Request-Reply component we need to place a Content Modifier with this header: x-csrf-token = Fetch

And one more thing - click anywhere in the canvas to enter the Integration Flow config, go to Runtime Configuration and set HTTP Session Reuse. This will assure that token is reused for any other subsequent call.

The iflow section which handles the token can look like this

After we run the iflow, the service will be called and we will receive the token and cookie in the response header. We don't need to extract them or handle them before calling the service to create Business Partner.
What we can do is to handle the http response. I chose a router, which routes the '200' response to positive scenario and any other response code to error handling subprocess.
CREATE BUSINESS PARTNER
Now let's go to create the Business Partner entity, which we will extend later to Customer.
We will be again calling the service:
/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner
Now we use the POST method, as we are sending data to SAP S/4.
Place a Content Modifier before the Request-Reply with content-type = application/json, as seen at the screenshot above. Like this we are telling the server what format we are sending.
The body has to be in json and have following format and syntax. We can set up a Business Partner with such as simple payload as this:
BusinessPartnerCategory decides whether the Business Partner will be Person (1), Organization (2) or Group (3).
More sophisticated payload to create an Organization can look like this:
Notice that we are using 'to_' prefixes for object extensions to be able to create Business Partner with address, email and telephone number. When we run the POST query, SAP will provide us with an XML response, which carries information about the newly created Business Partner.
As we will need the Business Partner number further in our iflow, we can extract the number via this XPath statement in Content Modifier:
//*[local-name()='properties']/*[local-name()='BusinessPartner']

We extracted the Business Partner number into a Property.
ASSIGN CUSTOMER ROLES
To extend our Business Partner to Customer, we need to assign it customer roles. We do this via another API.
URL: /sap/opu/odata/SAP/API_BUSINESS_PARTNER/A_BusinessPartnerRole
Method: POST
Headers: Content-type = application/json
Sample body:
The same call we use to assign any other role (like FLCU01), just modify the value in body.
CREATE CUSTOMER IN SALES AREA
Now we need to set Sales area data for our Customer.
URL: /sap/opu/odata/SAP/API_BUSINESS_PARTNER/A_Customer('BP number of newly created Business partner')/to_CustomerSalesArea
Method: POST
Headers: Content-type = application/json
Sample body (we are also setting a fixed Payer for demonstration):
CREATE CUSTOMER IN COMPANY CODE
And similarily for Company code data.
URL: /sap/opu/odata/SAP/API_BUSINESS_PARTNER/A_Customer('BP number of newly created Business partner')/to_CustomerCompany
Method: POST
Headers: Content-type = application/json
Sample body:
Our Customer should now be all set for basic business operations.
Notice that SAP responds to our calls in XML format. If for some reason you need to convert it to JSON, use an XML to JSON converter component, or use header Accept = application/json in your query. By that you are telling SAP to provide response in JSON.