SAP Commerce Cloud is a comprehensive e-commerce platform that enables businesses to deliver personalized, omnichannel shopping experiences across all touchpoints, helping companies accelerate digital commerce transformation and drive revenue growth.
The ballerinax/sap.commerce.webservices package offers APIs to connect and interact with SAP Commerce Cloud API endpoints, specifically based on SAP Commerce Web Services API v2.
To use the SAP Commerce Web Services connector, you must have access to the SAP Commerce Cloud API through a SAP Commerce Cloud developer account and obtain API credentials. If you do not have a SAP Commerce Cloud account, you can sign up for one here.
-
Navigate to the SAP Commerce Cloud website and sign up for an account or log in if you already have one.
-
Ensure you have access to SAP Commerce Cloud, as the Web Services API requires a valid Commerce Cloud subscription or trial environment.
-
Log in to your SAP Commerce Cloud Administration Console (Backoffice).
-
Navigate to System → API → OAuth2 Clients.
-
Create a new OAuth2 client by clicking the "+" button and configure the client with appropriate scopes and grant types for web services access.
-
Note down the Client ID and Client Secret that are generated for authentication with the Commerce Web Services API.
Tip: You must copy and store these credentials somewhere safe. The client secret won't be visible again in your account settings for security reasons.
To use the sap.commerce.webservices connector in your Ballerina application, update the .bal file as follows:
import ballerina/oauth2;
import ballerinax/sap.commerce.webservices as sapcommerce;- Create a
Config.tomlfile with your credentials:
clientId = "<Your_Client_Id>"
clientSecret = "<Your_Client_Secret>"
refreshToken = "<Your_Refresh_Token>"- Create a
sapcommerce:ConnectionConfigand initialize the client:
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
final sapcommerce:Client sapCommerceClient = check new({
auth: {
clientId,
clientSecret,
refreshToken
}
});Now, utilize the available connector operations.
public function main() returns error? {
sapcommerce:B2BCostCenter newCostCenter = {
code: "CC001",
name: "Marketing Cost Center",
activeFlag: true,
currency: {
isocode: "USD",
name: "US Dollar"
}
};
sapcommerce:B2BCostCenter response = check sapCommerceClient->createCostCenter("electronics", newCostCenter);
}bal runThe sap.commerce.webservices connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:
- Procurement cost center setup - Demonstrates how to set up and configure procurement cost centers using the SAP Commerce Web Services connector.
- Catalog inventory management - Illustrates managing product catalogs and inventory levels through SAP Commerce Web Services.
- Support ticket management - Shows how to create, update, and manage customer support tickets.
- Customer service workflow - Demonstrates implementing automated customer service workflows and processes.
-
Download and install Java SE Development Kit (JDK) version 21. You can download it from either of the following sources:
Note: After installation, remember to set the
JAVA_HOMEenvironment variable to the directory where JDK was installed. -
Download and install Ballerina Swan Lake.
-
Download and install Docker.
Note: Ensure that the Docker daemon is running before executing any tests.
-
Export Github Personal access token with read package permissions as follows,
export packageUser=<Username> export packagePAT=<Personal access token>
Execute the commands below to build from the source.
-
To build the package:
./gradlew clean build
-
To run the tests:
./gradlew clean test -
To build the without the tests:
./gradlew clean build -x test -
To run tests against different environments:
./gradlew clean test -Pgroups=<Comma separated groups/test cases>
-
To debug the package with a remote debugger:
./gradlew clean build -Pdebug=<port>
-
To debug with the Ballerina language:
./gradlew clean build -PbalJavaDebug=<port>
-
Publish the generated artifacts to the local Ballerina Central repository:
./gradlew clean build -PpublishToLocalCentral=true
-
Publish the generated artifacts to the Ballerina Central repository:
./gradlew clean build -PpublishToCentral=true
As an open-source project, Ballerina welcomes contributions from the community.
For more information, go to the contribution guidelines.
All the contributors are encouraged to read the Ballerina Code of Conduct.
- For more information go to the
sap.commerce.webservicespackage. - For example demonstrations of the usage, go to Ballerina By Examples.
- Chat live with us via our Discord server.
- Post all technical questions on Stack Overflow with the #ballerina tag.