Skip to content

Under the SAP Commerce Cloud platform, the Commerce Web Services API enables you to manage all common commerce functionality. This web services API URL is /api/commerce_webservices/.

License

Notifications You must be signed in to change notification settings

ballerina-platform/module-ballerinax-sap.commerce.webservices

Repository files navigation

Ballerina sap.commerce.webservices connector

Build Trivy GraalVM Check GitHub Last Commit GitHub Issues

Overview

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.

Setup guide

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.

Step 1: Create a SAP Commerce Cloud Account

  1. Navigate to the SAP Commerce Cloud website and sign up for an account or log in if you already have one.

  2. Ensure you have access to SAP Commerce Cloud, as the Web Services API requires a valid Commerce Cloud subscription or trial environment.

Step 2: Generate API Credentials

  1. Log in to your SAP Commerce Cloud Administration Console (Backoffice).

  2. Navigate to System → API → OAuth2 Clients.

  3. Create a new OAuth2 client by clicking the "+" button and configure the client with appropriate scopes and grant types for web services access.

  4. 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.

Quickstart

To use the sap.commerce.webservices connector in your Ballerina application, update the .bal file as follows:

Step 1: Import the module

import ballerina/oauth2;
import ballerinax/sap.commerce.webservices as sapcommerce;

Step 2: Instantiate a new connector

  1. Create a Config.toml file with your credentials:
clientId = "<Your_Client_Id>"
clientSecret = "<Your_Client_Secret>"
refreshToken = "<Your_Refresh_Token>"
  1. Create a sapcommerce:ConnectionConfig and initialize the client:
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;

final sapcommerce:Client sapCommerceClient = check new({
    auth: {
        clientId,
        clientSecret,
        refreshToken
    }
});

Step 3: Invoke the connector operation

Now, utilize the available connector operations.

Create a new cost center

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);
}

Step 4: Run the Ballerina application

bal run

Examples

The sap.commerce.webservices connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:

  1. Procurement cost center setup - Demonstrates how to set up and configure procurement cost centers using the SAP Commerce Web Services connector.
  2. Catalog inventory management - Illustrates managing product catalogs and inventory levels through SAP Commerce Web Services.
  3. Support ticket management - Shows how to create, update, and manage customer support tickets.
  4. Customer service workflow - Demonstrates implementing automated customer service workflows and processes.

Build from the source

Setting up the prerequisites

  1. 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_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.

  4. Export Github Personal access token with read package permissions as follows,

    export packageUser=<Username>
    export packagePAT=<Personal access token>

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 environments:

    ./gradlew clean test -Pgroups=<Comma separated groups/test cases>
  5. To debug the 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

About

Under the SAP Commerce Cloud platform, the Commerce Web Services API enables you to manage all common commerce functionality. This web services API URL is /api/commerce_webservices/.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 5