As enterprises move towards more interconnected and data-driven applications, the need to efficiently access and manipulate business data across SAP systems has never been greater. SAP Graph offers a unified API to connect, navigate, and interact with diverse SAP data sources through a single, graph-based interface.
In this article, we explore how to work with SAP Graph within SAP Business Application Studio (BAS)—SAP’s cloud-based integrated development environment—enabling developers to build seamless, scalable business applications on SAP Business Technology Platform (BTP).
SAP Graph is a powerful API gateway that abstracts data from multiple SAP systems (like S/4HANA, SuccessFactors, Ariba, and more) into a unified, semantically rich graph model. It allows developers to query and mutate business data easily, avoiding the complexity of dealing with multiple disparate APIs.
Start by launching a Dev Space in BAS with the necessary tools (Node.js, SAP Fiori, or CAP).
Use the SAP Graph SDK for JavaScript to interact with SAP Graph.
In the BAS terminal, run:
npm install @sap/graph-client
SAP Graph requires OAuth tokens issued by SAP BTP's XSUAA service. Configure your default-env.json or environment variables with credentials.
Example environment variables:
{
"sap.cloud": {
"uaa": {
"clientid": "<client-id>",
"clientsecret": "<client-secret>",
"url": "<uaa-url>"
}
},
"sap.graph": {
"url": "<sap-graph-url>"
}
}
In your Node.js project, initialize the client:
const { GraphClient } = require('@sap/graph-client');
const graphClient = new GraphClient({
url: process.env.SAP_GRAPH_URL,
auth: {
clientId: process.env.UAA_CLIENTID,
clientSecret: process.env.UAA_CLIENTSECRET,
tokenUrl: process.env.UAA_URL
}
});
To fetch data (e.g., list of purchase orders):
async function getPurchaseOrders() {
try {
const result = await graphClient.get('/businessPartner/purchaseOrders');
console.log(result.data);
} catch (error) {
console.error('Error fetching purchase orders:', error);
}
}
SAP Graph exposes relationships allowing deep data queries:
const purchaseOrdersWithItems = await graphClient.get(
'/businessPartner/purchaseOrders?$expand=items'
);
BAS enables building SAP Fiori apps that consume SAP Graph APIs:
SAP Graph simplifies accessing complex SAP data landscapes by providing a unified, graph-based API, ideal for modern cloud applications. When combined with the development power of SAP Business Application Studio, developers can rapidly build intelligent, scalable SAP applications that drive business innovation.
By mastering SAP Graph in BAS, SAP professionals unlock new possibilities to connect, visualize, and manipulate enterprise data seamlessly.