Using Common APIs

Objective

After completing this lesson, you will be able to use API used in SAP

Introducing to REST

In this lesson, the following topics are discussed:

  • What is REST?
  • Realization as a Web API.

What Is REST?

Generally, REST describes a machine-to-machine interface. In web development, REST allows content to be rendered when it's requested, often referred to as Dynamic Content. RESTful Dynamic Content uses server-side rendering to generate a website and send the content to the requesting web browser, which interprets the server’s code and renders the page in the user’s web browser.

Architectural properties

The constraints of the REST architectural style affect the following architectural properties:

  • Performance in component interactions, which can be the dominant factor in user-perceived performance and network efficiency.
  • Scalability allowing the support of large numbers of components and interactions among components.
  • Simplicity of a uniform interface.
  • Modifiability of components to meet changing needs (even while the application is running).
  • Visibility of communication between components by service agents.
  • Portability of components by moving program code with the data.
  • Reliability in the resistance to failure at the system level in the presence of failures within components, connectors, or data.

Architectural Constraints

The REST architectural style defines the following six guiding constraints:

  • Client–server architecture
  • Stateless
  • Cache-ability
  • Layered system
  • Code on demand (optional)
  • Uniform interface

Realization as a web API

Web service APIs that adhere to the REST architectural constraints and properties are called RESTful APIs. HTTP-based RESTful APIs are defined with the following aspects:

  • A base URL, such as http://api.example.com/.
  • Standard HTTP methods (for example: GET, POST, PUT, and DELETE).
  • A media type that defines state transition data elements (for example, Atom, microformats, application/vnd.collection+json). The current representation tells the client how to compose requests for transitions to all the next available application states.

Sources

A great deal of information can be found on the internet in the shape of texts, videos, podcasts, and more about REST. There are also various books about this topic from different perspectives:

Summary

A RESTful web API is created with the REST software architecture style. The interface must correspond to both the architectural properties and the constraints. This results in an implementation that, in addition to a base URI, uses standard HTTP methods and supports many media types. This places RESTful Web APIs at the heart of an API First Approach (architecture).

Introduction to OData

In this lesson, the following topics are discussed:

  • What is OData?
  • Architectural constraints
  • Tutorial: Learn about OData Fundamentals

What Is OData?

In computing, Open Data Protocol (OData) is an open protocol that allows the creation and consumption of queryable and interoperable RESTful APIs in a simple and standard way. OData builds on HTTP, AtomPub, and JSON using URIs to address and access data feed resources. It enables information to be accessed from various sources including (but not limited to) relational databases and file systems.

Architectural Constraints

The following constraints must be fulfilled:

  • Resource identification
  • Fixed documents
  • The service document
  • The metadata document
  • Dynamic resources
  • Resource operation
  • Querying
  • Resource representation

The following are explanations about the constraints:

Resource identification

OData uses URLs to identify resources. We use the following base URL with:

https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/

Fixed documents

The following fixed resources can be found:

The service document

The service document lists entity sets (collections), functions, and singletons that can be retrieved. Clients can use the service document to navigate the model in a hypermedia-driven fashion. The service document is accessed directly with the base URL: https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/. Below is an example from a later exercise.

Screenshot of a service document.
The metadata document

The metadata document describes the types, sets, functions, and actions understood by the OData service. Clients can use the metadata document to understand how to query and interact with entities in the service.

The metadata document is available at: https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/$metadata.

Screenshot of the metadata document.
Dynamic resources

The URLs for the dynamic resources can be computed from the hypermedia information in the service and metadata documents. The data feed for the ProductSet collection also contains links to other entities. The URL is as follows: https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/ProductSet

Screenshot of dynamic resources.
Resource operation

OData uses the HTTP verbs to indicate the operations on the resources. This is a REST aspect, as we have already seen.

Querying

URLs requested from an OData endpoint can include query options. The OData protocol specifies various system query options that endpoints can accept, they can be used to filter, order, map, or paginate data. In the following, only the product with the product number HT-1000 is retrieved. The URL is: https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC/ProductSet('HT-1000')

Screenshot of querying.
Resource representation

OData uses different formats for representing data and the data model. In OData protocol version 4.0, JSON format is the standard for representing data, with the Atom format still being in the committee specification stage. For representing the data model, the Common Schema Definition Language (CSDL) is used, which defines an XML representation of the entity data model exposed by OData services.

Tutorial: Learn about OData Fundamentals

There is a fantastic tutorial Learn about OData Fundamentals with the following topics:

  • Where OData came from and why it’s designed the way that it is.
  • What the standard OData operations are and how they relate to HTTP.
  • What the public Northwind OData service has to offer.
  • What OData service documents and metadata documents describe.
  • The basics of OData entity types, sets, and relationships.

It is recommended that you work through this tutorial to get fully acquainted with OData at SAP.

Summary

The OData protocol describes a RESTful Web API. In addition to the REST principles, it also offers other advantages that are beneficial in the professional environment. The interface itself provides two meta documents, service and meta document. This comprehensively describes the interface. The most effective function is the ability to filter, search, and execute functions such as $count via query parameters on the interface. The representation takes place either in XML or JSON.

Explore the APIs From the SAP Gateway Demo System

Business Scenario

In this exercise, we examine the GWSAMPLE_BASIC service. This sample service is based on the Enterprise Procurement Model (EPM). We want to use the APIs directly to find the customerID and the associate address data for the productID HT-1000.

Documentation of GWSAMPLE_BASIC: Sample Service - Basic

Task Flow

In this exercise, you perform the following tasks:

  1. Check if the productID HT-1000 is available.
  2. Get the Sales Order IDs to the productID HT-1000.
  3. Find the respective customer for each order of the productID HT-1000.

Prerequisites

You have access to the SAP Demo Gateway system ES5.

Outcome After This Exercise

You check whether all OData APIs required later can be called up and that technical data, for example, the productID HT-1000, is available.

What Do You Learn Within This Exercise

You get to know the OData APIs to be used later. You understand the OData model.

Task 1: Check If the ProductID HT-1000 Is Available

Steps

  1. Check if the productID HT-1000 is available.

    1. Choose the following link: Check for HT-1000

    2. If the productID exists, you get a data record to this productID.

      XML file as response to check whether ProductID exists.
    3. Check out the response.

Task 2: Get the Sales Order IDs to the ProductID HT-1000

Steps

  1. How many sales orders are there for the product HT-1000?

    1. Choose the following link: Count the SalesOrders

    2. Check the result:

      It shows that 1400 sales orders for the product HT-1000 are there.

      Note

      It is possible that the count gives you a different value than the one shown in the screenshot. The reason for that is that the system is reloaded cyclically with products.

  2. Find the Sales Order ID and Item Position for the productID HT-1000.

    1. Choose the following link: Check SalesOderID and ItemPosition

      XML file where the SalesOrderID and ItemPosition for product HT-1000 are shown.
    2. The OData navigation/ToHeader is used to find out the customerID. Therefore, we need the SalesOrderID and ItemPosition for every dataset entry.

Task 3: Find the Respective Customer for Each Order of the ProductID HT-1000

Steps

  1. Find the CustomerIDs for all SalesorderIDs and ItemPositions.

    1. Choose the following link: Check the CustomerID

      CustomerID for SalesOrderID is shown.
    2. You get a dataset with the CustomerID.

  2. Find the address data to one customer.

    1. Choose the following link: Check the communication data

      URL shows the address data for a customer.
    2. You get the address data for notification for every customer.

SAP Graph

In this lesson, the following topics are discussed:

  • What is SAP Graph?
  • SAP Graph is a Data Graph
  • Sample Data Graph
  • Developing SAP Graph APIs

What Is SAP Graph?

SAP Graph is a unified API for SAP, using modern open standards like OData v4. SAP Graph is one connection to your business data. SAP Graph introduces a new, unified API to access all business data as a single, semantically connected, Business Data Graph.

The graphic shows the Business Data Graph. A summary is provided in the following text.

Summary:

  • SAP Graph is based on *OData v4*.
  • Any SAP backend can be used as a data supplier.
  • There are already fully implemented APIs at: https://api.sap.com/graph.
  • You can create your own APIs with different procedures.

SAP Graph Is a Data Graph

Data graphs support queries that explore the data and the relationships.

The graphic shows the SAP graph as a data graph. Information of a data graph is provided in the following paragraph.
A data graph represents entities (data objects) as nodes of a graph:
  • Entities are grouped in namespaces.
  • The fields of an entity are called attributes.
Edges represent semantic relations:
  • Between a root-node and its sub-nodes: a composition.
  • Between independent nodes: an association.

Sample Data Graph

An example should illustrate the idea.

The graphic shows an example of a sample data graph. Information about the SAP Graph API is provided in the next paragraph.

An SAP Graph API with name product, using the namespace sap.graph is linked to product entities from the SAP S/4HANA* (No. 2) and from the SAP Sales Cloud (No. 3). The new API thus offers an extended view of product data stored in various SAP systems.

Developing SAP Graph APIs

There are two options to create an SAP Graph API. You can create APIs directly via an implementation with the SAP Graph module in Node.js. Under Source, you will find 26 video tutorials that show all the development steps in detail. A second approach from the field of low code is offered via SAP API Management.

Screenshot of how to develop SAP Graph APIs on SAP.

Resources

Summary

SAP Graph is an API based on OData v4 that connects entities from different sources in one API. For example, product data from various SAP systems, such as SAP S/4HANA, Sales Cloud, and others, is offered in one API. There are already standard SAP Graph APIs for various entities. SAP Graph APIs can be programmed with Node.js as well as created via SAP API Management in low code mode.

Log in to track your progress & complete quizzes