SAP API examples: an OData call and a BAPI call
These API examples show calling SAP over its interfaces, an OData request, a BAPI call, illustrating how external and custom code interacts with SAP data.
Two API calls in SAP's two dominant styles. OData: GET A_BusinessPartner from API_BUSINESS_PARTNER with $top=5, a bearer token and Accept application/json, the pattern for web and cloud. BAPI: CALL FUNCTION BAPI_MATERIAL_GET_DETAIL from ABAP with the material exported and general data and RETURN imported. Authenticate properly, check HTTP status or RETURN, use released APIs.
- Watch out: Skipping result/error checks.
- Worked examples: odata (external call), bapi (abap), what it teaches.
- How API examples fits into SAP development and the wider SAP landscape
OData (external call)
GET /sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner?$top=5
Authorization: Bearer <token>
Accept: application/jsonBAPI (ABAP)
CALL FUNCTION 'BAPI_MATERIAL_GET_DETAIL'
EXPORTING material = lv_matnr
IMPORTING material_general_data = ls_data
return = ls_return.What it teaches
The examples show the two dominant styles: modern OData/REST (JSON over HTTP, token auth, query options) for web/cloud, and classic BAPI/RFC for program-level SAP access. Always authenticate properly, check results (HTTP status or RETURN), and use released APIs from the Business Accelerator Hub.
Common pitfalls
- Skipping result/error checks.
- Hard-coded credentials.
- Using unreleased interfaces.