12

unable to get BTP Destination in CAPM service

 7 months ago
source link: https://community.sap.com/t5/technology-q-a/unable-to-get-btp-destination-in-capm-service/qaq-p/13599173
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

unable to get BTP Destination in CAPM service

sweetysingh

Participant

Thursday

- last edited

Friday

Hello CAPM Experts,

I am new to CAPM and looking for guidance in below scenario.

My CAPM should be able to connect Hana cloud as well as SAP ECC to achieve some business scenario.

I have created a CAPM project which connects to Hana cloud and able to fetch data from hana cloud through HDI container.

I have a Destination in BTP CF under destination tab which connects SAP ECC through Cloud connector.

I wanted to build one more microservice in same CAPM project which should connect to SAP ECC Odata endpoint using executeHttpRequest by passing this destination. Below is code in srv/routes/getMData.js

const core = require('@sap-cloud-sdk/core');

async function getData() {
const sDestinationName =  "<mydestinationName>";
    return new Promise(async (resolve, reject) => {
        try {
            let response = await core.executeHttpRequest({ destinationName: sDestinationName}, {
                method: 'GET',
                url: "/sap/opu/odata/sap/blabla_SRV/EntityDataSet",
                dataType: "JSON",
                contentType: "application/json",
            });
            if (response.status === 200) {
                resolve({ date: response.data });
            } else {
                resolve({ message: "error"});
            }
        } catch (error) {
            resolve({ message: "Error while reading Odata: "+ error.message });
        }
    });
}

Above code does not work and gives error: "message": "Error while reading Odata: Failed to load destination."

Then I realized, @Sap-cloud-sdk/core is deprecated. And we should be using below 2 packages

  • @Sap-cloud-sdk/connectivity contains all Cloud Foundry connectivity service related methods like getDestination().
  • @Sap-cloud-sdk/http-client contains the http client with built-in connectivity with executeHttpRequest().
const connect = require('@sap-cloud-sdk/connectivity');
const dest= require('@sap-cloud-sdk/http-client');

async function getData() {

const sDestinationName= await connect.execute({ destinationName: '<mydestinationName>'});
    return new Promise(async (resolve, reject) => {
        try {
            let response = await dest.executeHttpRequest({ destinationName: sDestinationName}, {
                method: 'GET',
                url: "/sap/opu/odata/sap/blabla_SRV/EntityDataSet",
                dataType: "JSON",
                contentType: "application/json",
            });

            if (response.status === 200) {
                resolve({ date: response.data });
            } else {
                resolve({ message: "error"});
            }
        } catch (error) {
            resolve({ message: "Error while reading Odata: "+ error.message });
        }
    });
}

Now I am getting error "message": "Error while reading SampleTypeError: dest.execute is not a function"

I am going through Destination | SAP Cloud SDK for JavaScript - v3.11.0 but unable to understand what exactly I should be to make it work.

Could someone please suggest?

Thanks,

Sweety.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK