cancel
Showing results for 
Search instead for 
Did you mean: 

How to consume one capm service in another capm service?

VenkyM
Participant
0 Kudos

Hello all,

I have two capm services serviceA and serviceB in two different capm projects. I need to call serviceB in serviceA and these two services are deployed in SAP BTP.
Is there a way to communicate and send data from serviceA to serviceB?
Any help is appreciated?
Thank you.

Accepted Solutions (0)

Answers (2)

Answers (2)

Kunal_Ingale_In
Discoverer
0 Kudos

Hi @VenkyM ,

You can attempt this solution by generating/exposing the service through an EDMX file as the exchange format, essentially exporting a service API to EDMX.

Use the below command : 

cds compile srv -s Servicename -2 edmx > Servicename.edmx

Then, export the "Servicename.edmx" file and import it into your new project to consume its contents within your project.

Use the below code to connect that service/API.

 

module.exports = cds.service.impl(async function() {
const { testentity } = this.entities;
const service = await cds.connect.to('servicename');
this.on('READ', testentity, request => {
return service.tx(request).run(request.query);
});
});

 

 

MioYasutake
Active Contributor
0 Kudos

@VenkyM 

You can find how to consume external services from CAP application in the document below:

https://cap.cloud.sap/docs/guides/using-services

VenkyM
Participant
0 Kudos


Hello @MioYasutake 
Thank you for your response.
Will it work from two CAPM services in two different CAM projects?
Should I use destinations or cds.connect(). Please clarify.

MioYasutake
Active Contributor
0 Kudos

@VenkyMIf you want to call serviceB from serviceA, please follow below steps:

  1. Create a destination for serviceB
  2. Import metadata of serviceB in the project of serviceA
  3. Use `cds.connect.to('ServiceB')` to connect to the serviceB
  4. Add the following configuration to package.json before deployment

 

"cds": {
  "requires": {
    "ServiceB": {
      "kind": "odata",
      "model": "srv/external/ServiceB",
      "[production]": {
        "credentials": {
          "destination": "<destination for serviceB>",
          "path": "/path/to/ServiceB"
        }
      }
    }
  }
}