Module sap
ballerinax/sap Ballerina library
Overview
SAP is a global leader in enterprise resource planning (ERP) software. Beyond ERP, SAP offers a diverse range of solutions including human capital management (HCM), customer relationship management (CRM), enterprise performance management (EPM), product lifecycle management (PLM), supplier relationship management (SRM), supply chain management (SCM), business technology platform (BTP), and the SAP AppGyver programming environment for businesses.
The ballerinax/sap package provides an HTTP client for interfacing with APIs across SAP's product suite. This client comes with built-in SAP system-complient CSRF token authentication.
Setup guide
In this guide, we'll be utilizing the S/4HANA Sales Order API to showcase the capabilities of the SAP Client.
Step 1: Login
- Sign in to your S/4HANA dashboard.
Step 2: Create a Communication System
-
Under the
Communication Managementsection, click on theDisplay Communications Scenariotitle.
-
In the top right corner of the screen, click
New.
-
Give a system id.

-
Give the hostname as your S/4HANA hostname.

-
Add
UsersforInbound Communication.
-
Select the
Authentication MethodandUser.
-
Click Save.
Step 3: Create a Communication Arrangement
-
Under the
Communication Managementsection, click on theDisplay Communications Scenariotitle.
-
In the search bar, type
Sales Order Integrationand select the corresponding scenario from the results.
-
In the top right corner of the screen, click on
Create Communication Arrangement.
-
Enter a unique name for the arrangement.

-
Choose an existing
Communication Systemfrom the dropdown menu and save your arrangement.
-
The hostname (
<unique id>-api.s4hana.cloud.sap) will be displayed in the top right corner of the screen.
Quickstart
To use the sap connector in your Ballerina application, modify the .bal file as follows:
Step 1: Import the module
Import the sap module.
import ballerinax/sap;
Step 2: Instantiate a new connector
configurable string hostname = ?; configurable string username = ?; configurable string password = ?; sap:Client sapClient = check new (string `https://${hostname}/sap/opu/odata/sap/API_SALES_ORDER_SRV`, { auth: { username, password } });
Step 3: Invoke the connector operation
Now, utilize the available connector operations.
json salesOrderList = check sapClient->/A_SalesOrder();
Step 4: Run the Ballerina application
bal run
Examples
The sap connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering use cases like accessing S/4HANA Sales Order (A2X) API.
- Send a reminder on approval of pending orders - This example illustrates the use of the
sap:Clientin Ballerina to interact with S/4HANA APIs. Specifically, it demonstrates how to send a reminder email for sales orders that are pending approval.