Skip to content

Ballerina SAP HTTP Client connector module.

License

Notifications You must be signed in to change notification settings

ballerina-platform/module-ballerinax-sap

Repository files navigation

Ballerina SAP Connector

Build codecov Trivy GraalVM Check GitHub Last Commit GitHub Issues

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-compliant 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

  1. Sign in to your S/4HANA dashboard.

Step 2: Create a Communication System

  1. Under the Communication Management section, click on the Display Communications Scenario title.

    Communication Systems
  2. In the top right corner of the screen, click New.

    Click New
  3. Give a system id.

    System Id
  4. Give the hostname as your S/4HANA hostname.

    Give Hostname
  5. Add Users for Inbound Communication.

    Add User
  6. Select the Authentication Method and User.

    Select User
  7. Click Save.

Step 3: Create a Communication Arrangement

  1. Under the Communication Management section, click on the Display Communications Scenario title.

    Display Scenarios
  2. In the search bar, type Sales Order Integration and select the corresponding scenario from the results.

    Search Sales Order
  3. In the top right corner of the screen, click on Create Communication Arrangement.

    Click Create Arrangement
  4. Enter a unique name for the arrangement.

    Give Arrangement Name
  5. Choose an existing Communication System from the dropdown menu and save your arrangement.

    Select Existing Communication Arrangement
  6. The hostname (<unique id>-api.s4hana.cloud.sap) will be displayed in the top right corner of the screen.

    View Hostname

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.

  1. Send a reminder on approval of pending orders - This example illustrates the use of the sap:Client in Ballerina to interact with S/4HANA APIs. Specifically, it demonstrates how to send a reminder email for sales orders that are pending approval.

Issues and projects

The Issues and Projects tabs are disabled for this repository as this is part of the Ballerina library. To report bugs, request new features, start new discussions, view project boards, etc., visit the Ballerina library parent repository.

This repository only contains the source code for the package.

Build from the source

Prerequisites

  1. Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources:

    Note: After installation, remember to set the JAVA_HOME environment variable to the directory where JDK was installed.

  2. Download and install Ballerina Swan Lake.

  3. Download and install Docker.

    Note: Ensure that the Docker daemon is running before executing any tests.

Build options

Execute the commands below to build from the source.

  1. To build the package:

    ./gradlew clean build
  2. To run the tests:

    ./gradlew clean test
  3. To build the without the tests:

    ./gradlew clean build -x test
  4. To run tests against different environment:

    ./gradlew clean test -Pgroups=<Comma separated groups/test cases>

    Tip: For detailed information, please refer to the Tests_README document.

    Groups Environment
    mock Mock server
    sap SAP S/4HANA API
  5. To debug package with a remote debugger:

    ./gradlew clean build -Pdebug=<port>
  6. To debug with the Ballerina language:

    ./gradlew clean build -PbalJavaDebug=<port>
  7. Publish the generated artifacts to the local Ballerina Central repository:

    ./gradlew clean build -PpublishToLocalCentral=true
  8. Publish the generated artifacts to the Ballerina Central repository:

    ./gradlew clean build -PpublishToCentral=true

Contribute to Ballerina

As an open-source project, Ballerina welcomes contributions from the community.

For more information, go to the contribution guidelines.

Code of conduct

All the contributors are encouraged to read the Ballerina Code of Conduct.

Useful links