Skip to Content
Product Information

Announcing the SAP Cloud SDK for JavaScript

TypeScript and JavaScript developers, this is for you: the SAP Cloud SDK (fka SAP S/4HANA Cloud SDK) is now available for JavaScript. Today, we are proud to release version 1.0.0 of the SAP Cloud SDK for JavaScript. This is the first generally available, productive version of the libraries for JavaScript, after the beta that started in October last year.

Similar to the SDK for Java, the SAP Cloud SDK for JavaScript makes it easy and delightful to develop extensions to SAP S/4HANA as applications on SAP Cloud Platform. The SAP Cloud SDK for JavaScript helps you to integrate SAP S/4HANA into your Cloud-native applications written in TypeScript or JavaScript, running in Node.js. You can execute those applications locally or deploy them to SAP Cloud Platform, Cloud Foundry.

Continue reading below if you want to get the high level picture on the most helpful features of the initial release and on how to access the JavaScript libraries of the SDK. If you want to get started quickly, head over to our tutorial series and begin using the SDK for JavaScript today. Like the SDK for Java, the SAP Cloud SDK for JavaScript is available free-of-charge under SAP Developer License.

Capabilities of the SDK for JavaScript

The following describes on a high-level the most important features. For more details, refer to the release notes and the API documentation in JSDoc.

Easy access to SAP S/4HANA Cloud APIs

Accessing SAP S/4HANA Cloud can be as easy as follows – no boilerplate, low-level code, just business logic:

import { BusinessPartner } from '@sap/cloud-sdk-vdm-business-partner-service';

BusinessPartner.requestBuilder()
    .getAll()
    .select(BusinessPartner.LAST_NAME)
    .filter(BusinessPartner.FIRST_NAME.equals("John"))
    .execute({destinationName: "S4HANACloud"})
    .then(businessPartners => {
        // process result of type BusinessPartner[]
    }).catch(reason => {
        // handle error
    });

This is made possible by the OData Virtual Data Model (VDM, also known from the SDK for Java). The OData VDM of the SDK for JavaScript provides a TypeScript/JavaScript representation of the OData API of SAP S/4HANA Cloud, including all services, operations and entity types listed on the SAP API Business Hub. In a similar manner as the code snippet above, you can access not only reading, but also writing operations (function imports are not yet supported).

Straightforward integration of SAP Cloud Platform

The code snippet above also illustrates the out-of-the-box integration with the destination service on SAP Cloud Platform for managing the target system, or destination, and authentication credentials. Don’t worry if you missed it at first glance – it’s easy to miss thanks to the straightforward integration: when calling execute on an OData VDM request, you pass the name of a destination, in this case, S4HANACloud. That’s it, the SDK will take care of resolving the destination defined in the destination service on SAP Cloud Platform and perform the required authentication.

If you prefer, you can also define the destination manually. In addition, it’s easy to substitute the destination service with simple environment variables when running locally or during tests.

TypeScript or JavaScript?

The above example uses TypeScript, a typed superset of JavaScript. If you are only familiar with JavaScript, you may not even have noticed, though. In fact, the above code is also perfectly valid JavaScript. The SAP Cloud SDK for JavaScript has been implemented in TypeScript, and can be used in JavaScript and TypeScript project alike. Both JavaScript and TypeScript developers can use the same libraries and get the same features, and both will benefit from the code completion capabilities enabled by TypeScript, given an editor with corresponding support. TypeScript projects of course will benefit from additional type-safety.

We can only encourage everyone to check if TypeScript suits his needs. If you don’t want to use TypeScript, it is still perfectly fine to stick to plain JavaScript and use the SDK in JavaScript.

Continuous delivery pipeline

The continuous delivery toolkit is a core component of the SAP Cloud SDK, because it enables projects to continuously deliver their application without additional effort for setting up a continuous delivery pipeline. We are happy that we are able from the very beginning to provide this out-of-the-box continuous delivery pipeline also for JavaScript projects.

To this end, we provide two project scaffolds, one for TypeScript and one for JavaScript projects. They out-of-the-box include everything needed to run the continuous delivery pipeline on a Jenkins server. You do not have to write a single line of pipeline code to benefit from the best practices codified in the pipeline, only configure it to your project environment. For more details on what is supported, take a look at the release announcement for version v17 of the continuous delivery toolkit.

How to Access the JavaScript Libraries

The JavaScript libraries of the SAP Cloud SDK are freely accessible from SAP’s npm registry. SAP’s registry works like the standard npmjs registry for resolving JavaScript modules. It hosts packages of the scope @sap. All you need to do to be able to retrieve the SDK modules, which are all provided with scope @sap, is executing the following command:

npm config set "@sap:registry" "https://npm.sap.com"

Afterwards, pick any module of the SDK listed on the module overview in the documentation and install it as a dependency into your Node.js project, for example:

npm install @sap/cloud-sdk-vdm-business-partner-service

Thank You!

Thanks a lot to the whole development team for the effort and dedication to make the release possible. We would also like to thank the many partners and customers that participated in the beta. Their feedback helped shape the version 1.0.0 of the SAP Cloud SDK for JavaScript.
Here’s what two SAP partners participating in the beta had to say:

  • Lars Schubert, managing director of graphomate GmbH, said about the SDK: “Our first tests of the SDK were very promising and we are excited to implement productive applications with it.” Jonas Vogler, Head of Software Development at graphomate GmbH, summarized the experience of the development team with the SDK as “easy to use, nice, reliable. That’s the future.”
  • Scott Stefanich, solution architect at pmc America, Inc., enjoyed working with the beta of the SAP Cloud SDK for JavaScript specifically because of the OData virtual data model: “The virtual data model is excellent. The combination of type-safety and auto-completion really improves your productivity and allows to focus on the task at hand.”

Now, we would like to invite everyone to experience this for themselves, use the SDK, ask questions on Stack Overflow, and give open feedback.

8 Comments
You must be Logged on to comment or reply to a post.
  • Thanks for such a nice blog, Really Helpful !!!

    I tried to use

    “https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_BUSINESS_PARTNER” instead of MockServer however , it needs APIKey along with credentials which seems to be not supported in destination.

    Can you please help me out how i can send it during  fetch call ? I tried below but it gives error –

     

    function getAllBusinessPartners(): Promise<BusinessPartner[]> {
    return BusinessPartner.requestBuilder()
    .getAll()
    .execute({
    url: ‘https://sandbox.api.sap.com/s4hanacloud’,
    username: ‘MyUserName’,
    password: ‘MyPass’,
    APIKey: ‘MyAPIKey’
    });
    }

     

    Error ->

    src/business-partner-route.ts:16:3 – error TS2345: Argument of type ‘{ url: string; username: string; password: string; APIKey: string; }’ is not assignable to parameter of type ‘Destination | DestinationNameAndJwt’.
    Object literal may only specify known properties, and ‘APIKey’ does not exist in type ‘Destination | DestinationNameAndJwt’.

     

    Thanks ,

    Mahesh Z.

    • Hi Mahesh,

      you can set the APIKey using the withCustomHeaders method on the request builder like this:

      BusinessPartner.requestBuilder()
        .getAll()
        .withCustomHeaders({
          'APIKey'; 'MyAPIKey'
        })
        .execute({
          url: ‘https://sandbox.api.sap.com/s4hanacloud’
        });

      (Plus I think you can skip username and password when providing an API key).

      Let me know if this works for you! If not, don’t hesitate to reach out to us for further questions.

      Best regards

      Dennis

      • Hi Dennis,

        Thanks for sharing the solution, That worked for me.

        Just couple of more things to clarify –

        1. How to add , Multiple Select , filters and also $Top and $Skip parameters to this call , is it supported ?
        2. It seems this will only work with S/4 HANA Cloud. Is there any way we can make this work with S/4 HANA OnPremise systems. How to use VDM in that case ? [Considering we have cloud connector setup with our onpremise systems and destination already setup and working].

         

        Thanks ,
        Mahesh Z.

        • Hi Mahesh,

          for all the OData operations there are corresponding functions on the request builder. Consider the following example:

          BusinessPartner.requestBuilder()
            .getAll()
            .select(
              BusinessPartner.FIRST_NAME,
              BusinessPartner.LAST_NAME,
              BusinessPartner.TO_CUSTOMER.select(
                Customer.CUSTOMER
              )
            )
            .filter(or(
              and(
                BusinessPartner.FIRST_NAME.equals('John'),
                BusinessPartner.LAST_NAME.equals('Doe'),
              ),
              and(
                BusinessPartner.FIRST_NAME.equals('First'),
                BusinessPartner.LAST_NAME.equals('Last'),
              )
            ))
            .top(5)
            .skip(5)
            .execute...
            

          This code example should give you a pretty good idea of what you can do. For more, check the documentation here: https://help.sap.com/viewer/product/SAP_S4HANA_CLOUD_SDK/1.0/en-US

          Regarding VDM on S/4HANA on-premise: While the VDM we ship in the SAP Cloud SDK is for S/4HANA Cloud, it should also work for on-premise as long as the APIs themselves are compatible between the two versions.

          • Thanks Dennis. That worked for me. I am now trying my luck with onPremise systems.

             

            Also , i tried to implement the same thing in plain JS but not getting the expected output – My Route Code is as follows –

             

            const express = require(“express”);
            const BusinessPartners = require(“@sap/cloud-sdk-vdm-business-partner-service”);

            exports.businessPartners = function(req, res) {
            res.status(200).send(getAllBusinessPartners());
            }

            function getAllBusinessPartners() {
            return BusinessPartners.requestBuilder()
            .getAll()
            .top(1)
            .skip(0)
            .execute({
            destinationName: ‘MyDest’
            });
            }

             

            Is there any correction required here ?

             

            Thanks ,
            Mahesh.

          • Your function getAllBusinessPartners returns a Promise<BusinessPartner[]>, so you will either have to await it:

            res.status(200).send(await getAllBusinessPartners());

            or call the function and then handle the response with then() (which I recommend because you can properly handle errors):

            getAllBusinessPartners()
              .then(businessPartners => {
                res.status(200).send(businessPartners);
              })
              .catch(error => {
                res.status(500).send(error.message);
              });
          • Hi Dennis,

            I am getting Internal Server Error as response.

            Can you please advice if below method declaration is correct ?

            function getAllMaterials() {
            return Materials.requestBuilder()
            .getAll()

            .withCustomHeaders({
            ‘APIKey’: ‘mcJX5Yp6iMh3jXlGbDt17vNzyWgARQ1E’
            }).top(1)
            .skip(0)
            .execute({
            destinationName: ‘Destination’
            });
            }

             

            Thanks ,

            Mahesh.