How Does SAP API (Application Programming Interface) Work?
Application Programming Interfaces, or APIs, are essential in the way we interact with technology today. In this article, we demystify APIs using SAP products as an example.
What is an API?
API stands for Application Programming Interface, where Interface is the key element. It serves as a bridge that allows different systems or applications to communicate and interact with one another.
Within an ERP system like SAP, data is organized and stored in a secure database. This data is protected by multiple layers of security and wrapped in lines of code that enforce a specific data model. To interact with this data, special tools such as modules, functions, or classes are created to enable specific read or write actions. These tools are collectively known as APIs.
Most modern applications and ERP systems include APIs to streamline communication with internal data. APIs play a vital role in facilitating interaction within complex computer ecosystems.
This blog delves into SAP APIs and their role in enabling seamless interactions in a computing environment. Let's begin by understanding their origins.
History of APIs
RFC (Remote Function Call)
Those familiar with SAP will likely know about BAPIs, though their exact identity may remain unclear. The term BAPI, which stands for Business API, refers to an SAP-specific concept with distinct attributes:
- Programming handled by an RFC-enabled function module, an SAP proprietary protocol allowing the Function to be called externally.
- A logic that implements a specific action of a Business Object (an SAP internal object representing a real-world entity, e.g., Purchase Order, Employee, etc.).
- For actions such as creation or update, the transactional LUW (Logical Unit of Work) is preserved. In simpler terms, one action occurs at a time, with no direct database commit.
- The function module is officially approved by SAP, ensuring its functionality and support during system upgrades.
SAP also provides libraries (connectors) for various programming languages, such as VB and Java, enabling custom systems to connect with SAP for specific actions. Many older custom systems and applications continue to rely on these tools today.
Web Services
Web services introduced more flexibility and compatibility by using standard communication protocols such as HTTP and SOAP. These protocols allow for easier integration between different systems and applications, supporting cross-platform interoperability.
With web services, APIs became more accessible and easier to deploy. SAP leveraged this approach to create a more open and connected ecosystem, allowing businesses to extend their capabilities without being confined to proprietary protocols.
Web Protocol Evolution in SAP
With the integration of web servers into SAP's application layer, communication via HTTP(S) protocol became possible. This method quickly replaced RFC as the preferred protocol for system integration, enabling the rise of web services for seamless device-to-device communication.
SOAP (Simple Object Access Protocol)
SOAP facilitates system communication using HTTP, transferring data in XML format. It has been widely adopted for automating business processes, such as vendor invoice transfers, shipping data exchanges, and delivery label creation. Many partners charge fees for SOAP API services based on usage volume.
For example, our development team has used SOAP APIs from Canada Post in SAP ECC and SAP S/4HANA to generate shipping labels and tracking numbers, storing them in SAP documents. Another project required SOAP calls between SAP S/4HANA and external systems like Concur or Trindocs for vendor data and invoice transfers.
REST (Representational State Transfer)
REST emerged as a lighter alternative to SOAP, focusing on efficient data interaction through existing web rules. Unlike SOAP, REST uses JSON (a lighter format than XML) and is ideal for mobile and web applications. REST APIs quickly gained popularity for their simplicity and performance.
OData
Developed by Microsoft in 2007, OData is an open-source protocol for standardizing REST API production and consumption. It simplifies working with object data models and was adopted by SAP for data transfers between its Fiori front end and the application layer.
Why APIs Matter for Business
APIs have become central to business strategies, often surpassing the popularity of the original product or service. Machine-to-machine API traffic now exceeds regular user traffic. Platforms like AWS and Microsoft Azure offer developer ecosystems where APIs are the focus, enabling innovation and collaboration.
This growing interest will spread to the point where we now have web platforms where APIs are the star (e.g., AWS). These platforms, like Microsoft Azure, offer a sort of blank slate where developers from all sources participate and add content which supports the platform.
We use APIs in our daily lives without realizing it
We've all shared some interesting news or other articles on our Facebook wall or Instagram profile. Just recently, I was pleasantly surprised to connect to my "Revenue Canada" account (which I don't know) using my personal bank account (which I know very well). Some video games will even, transparently, use third-party storage APIs to save a player's progress and preferences. These interactions are made by APIs.
Human interaction is being eclipsed by more and more applications (including mobile) communicating with each other by REST APIs, creating some sort of social network for machines.
SAP Cloud Platform APIs (SCP)
With the appearance of SAP Cloud applications, developers no longer have access to the application layer to manipulate data or processes. SAP provides a growing list of APIs to developers to accomplish this interaction.
SAP API Business Hub
To consolidate and facilitate searching for all sorts of APIs for different cloud products, SAP launched its API Business Hub. Here's an example of a search for APIs in the purchasing domain, and their different formats:
The SAP API Business Hub even allows generating snippets of code in different languages to facilitate API consumption. SAP offers a sandbox with real data for quickly and easily testing APIs. The list and its organization evolve continuously, so we must stay tuned!
SAP Cloud Platform API Management
SAP's Cloud Platform (SCP) offers a service called API Management. Here, we can expose our own APIs, create products (API combinations), add security or other required limitations, track consumption, evaluate statistics and errors, and more.
Using the integration with the WebIDE, we can even create Fiori apps based on a template and embed in our app a call to one of these APIs.
I have personally spent many hours over the years looking for details on different actions of an API, following the sometimes very thin and scattered documentation found all over the Internet. The quality and format of information found today is a clear improvement.
With this sort of gathering and homogenization of information, as well as the automatic generation of pieces of code, it has never been easier to develop professional and integrated applications.