4

CAP Meeting SAP Graph Embrace the power of SAP Business Technology Platform

 1 year ago
source link: https://blogs.sap.com/2023/07/05/cap-meeting-sap-graph-embrace-the-power-of-sap-business-technology-platform/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
  • Overcoming Data Integration Challenges: Introducing SAP Graph as a Unified Solution for Multiple Business Systems

  • Business Problem — You got multiple business systems for example SAP S/4 HANA Cloud / SAP SuccessFactors / SAP S/4 HANA System on Premise but bringing data from these systems using one Unified service is a challenge but that Change got a beautiful solution and that is SAP Graph

         SAP Graph  “providing developers with a single connected and unified view of all their business data

        SAP Graph  “A Single Endpoint for All Purposes: Streamlining Functionality” 

Resources & Credit:

  •      Before I get into implementation details, I would like to give credit to SAP HANA Academy         for such a great Youtube Series on SAP Graph please follow it for building your solutions         end-2-end.
  •      You can also follow SAP Graph tag on SAP Community and blog series on SAP Graph

Pre-requisites:

  1.      BTP Cockpit trial account or Paid Account
  2.      SAP graph Free tier Services ( Check SAP Discovery Center for more detail )
  3.      Create Graph instance and Key Service Key ( Download and Save it )
  4.      Graph Instance parameters – ( Download and save it ) More details on HANA Academy git       hub  – > SAP Graph
  5.      Go to PowerShell or VS Code and install graphctl tool for graph connect

Setup Graph Environment:

Get your free tier service from SAP Discovery center and add the entitlement in your BTP Subaccount

       

1-30.png

Download your graph key and store it somewhere in your system ( I will not go into detail as there are already few blogs and series on how to set it up but this is needed for start hence adding it for connect)

Destination Configuration:

Get your API Key and API url from SAP’ API Sandbox system.

Business Acceleration Hub –  https://api.sap.com/api/businesspartner/overview

Login with your credentials – go to -> Settings -> Show API Key – Copy and Save it Somewhere

Create destination in BTP Cockpit

Destination Config will look like this :-

2-14.png

Lets go to PowerShell or VS Code whatever suits you

Here is my VSCode window and I will login into my BTP Account

       

3-14.png
  • Enter credentials and connect to your Dev Space
  • Install graphctl tool using npm : Execute command – npm i @sap/graph-toolkit
  • Login into graph using Graphctl login using credentials saved 

     

4-10.png

      Note: It will open web browser for login,please login using BTP Cred and we are connected to Graph Instance at BTP Cockpit now

Let’s see if it is connected correctly

Execute : graphctl generate config -f “C:\Users\Yoga\Desktop\graph\instance-parameters.json” -i cxsales

4.5.png
5-10.png

Lets list the graph config now but before that Activate the config.

Activate Config:

graphctl activate config -f “C:\Users\Yoga\Desktop\graph\instance-parameters.json” –force

List Config:

graphctl list config

   

6-9.png

We are connected with SAP graph now and this is ready to serve you -> Generate your Service keys on graph instance and go to Postman and you can start testing your graph API

Here are few test case which I have captured:

sap.graph is serving successfully the Cloud for customer entities here – you can choose/select any entity and can consume or bind with your application directly this is the power of SAP Graph – Amazing tech with Amazing Results  

 

7-10.png

lets Choose “Company”

   

8-9.png

Ok here we are done with the Setup and testing with Postman

lets do some CAP Development Now…

Attaching high level CAP Application Architecture

 

SAP-Graph.png

Go to your VS Code or BAS ( Your Preference ) I am using VS Code for CAP Development

What all we need ?

  1.      Node in your VS Code
  2.      Destination for Graph endpoint in BTP Cockpit
  3.      Authentication , Destination and connectivity services in CAP

Install Node in your VS Code if not done – Follow

Create Destination in BTP Cockpit in the same way as we did for Cloud for Customer APIs – Get Client ID and secret from Graph Service Key file

Go to your VS Code

Execute these command in Sequence

cds init 

cds add mta 

Go to package.json

Add this CDS Section

"cds": {
    "requires": {
      "shagraph": {
        "kind": "odata-v4",
        "credentials": {
          "destination": "shagraph",
          "path": "/sap.graph"
        }
      }
    }
  }

Add sales.cds  file in srv folder and add the below snippet

@protocol: 'rest'
service root {
    @open
    type object {};
    function graph(name:String) returns array of object;
}

Add sale.js file in srv folder

const get = require("./handlers/GET/getSales");

module.exports = cds.service.impl(async function () {
  this.on("graph", get.graph);
});

handler for graph.

const graph = async (req) => {
  const srv = await cds.connect.to("shagraph");
  if (req.data.name !== null && req.data.name != undefined) {
    req.query = SELECT.from(req.data.name);
  } else {
    req.query = SELECT.from(`sap.graph`);
    req.query.SELECT.from.ref[0] = "";
  }
  return await srv.run(req.query);
};

module.exports = {
  graph
};

Lets try to build it using mbt build and deploy this application to cloud foundry – cf deplpy mtar 

Testing of the Application locally in VS Code:

Call the graph: 

GET http://localhost:4004/root/graph()
10-5.png

Call the Entity: 

GET http://localhost:4004/root/graph(name=’Country’)
11-5.png

Call the Entity: 

GET http://localhost:4004/root/graph(name=’Company’)
12-2.png

Here CAP Endpoint is serving first for sap.graph and after that we are passing entities exposed using business data graph and it comes to an end then.

I hope you have enjoyed the reading and please feel free to post your comments or questions if any 🙂

Thanks Shivam


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK