Querying SAP APIs in JavaScript or TypeScript

After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Query an SAP API using the SAP Cloud SDK in a JavaScript and TypeScript program

Consulting the SAP Cloud SDK for JavaScript Reference Documentation

Access the reference documentation

The reference documentation of SAP Cloud SDK can be accessed via the following steps:

  1. Open: https://sap.github.io/cloud-sdk
  2. Choose Get started with the SDK for JavaScript.

The Core Libraries

The SDK consists of a few core libraries and a number of API-specific pregenerated libraries..

The core libraries are:

  • @sap-cloud-sdk/connectivity: The connectivity library provides functionality to read and exchange with services like the destination, XSUAA and connectivity service. It provides the basic types needed to reflect the concept of a destination throughout the SAP Cloud SDK for JavaScript.
  • @sap-cloud-sdk/http-client: The HTTP client library is a thin HTTP client, that allows you to execute requests by leveraging the concept of destinations. You can flexibly configure a request to your needs and send arbitrary HTTP requests to the given destination.
  • @sap-cloud-sdk/odata-v2, @sap-cloud-sdk/odata-v4, and @sap-cloud-sdk/openapi: The OData v2, v4, and OpenAPI libraries build the foundation for client libraries (custom and pregenerated). They contain OData and OpenAPI specific abstractions, that the client libraries use to expose their APIs.
  • @sap-cloud-sdk/generator and @sap-cloud-sdk/openapi-generator: The OData and OpenAPI generators are CLIs that generate client libraries based on the services' specifications (either EDMX format or OpenAPI/Swagger). You can use them to generate your own clients. The pregenerated client libraries are generated using these generators.

Pregenerated Libraries

While you can generate your own libraries, the SAP Cloud SDK for JavaScript provides pregenerated client libraries for the SAP S/4HANA Cloud and On-Premise APIs as well as the SAP Workflow service. These libraries are published under the SAP Developer license agreement and are free to use.

Pregenerated Libraries are API specific. The reference to their documentation can be found in the SAP API Business Hub. For example try the following steps:

  1. Open: https://api.sap.com
  2. Search: Business Partner A2X
  3. Click on the first API
  4. Choose the SAP Cloud SDK tab.
  5. Choose the JavaScript tab.
  6. Choose the link of the NPM Repository.

Using the libraries to consume the SAP APIs

Information about the way to use the libraries to interact with the SAP APIs is described in the following pages of the standard documentation:

Save progress to your learning plan by logging in or creating an account