Skip to Content
1
Mar 04, 2021 at 08:14 PM

Accessing CF Destination from a Node.js application ( VError: No service matches cfServiceName )

319 Views Last edit Mar 05, 2021 at 07:20 AM 2 rev

Hi,

First of all, i'm new to CAP.

I'm following examples from github using sapmentors/cds-scp-api extension.

While accessing the CF target from the node.js application using @ sapmentors / cds-scp-api, I encountered a problem that I detailed below. I use Northwind as a destination. Has anyone encountered this kind of error? Obviously i'm missing something but couldn't figure it out.

[ERROR] VError: No service matches cfServiceName at Object.getServices (/home/user/projects/norgit/node_modules/@sapmentors/cds-scp-api/node_modules/@sap/xsenv/lib/xsservices.js:50:15) at Object.getVCAPService (/home/user/projects/norgit/node_modules/@sapmentors/cds-scp-api/lib/scp-utils.js:20:33) at Promise (/home/user/projects/norgit/node_modules/@sapmentors/cds-scp-api/lib/scp-destinations.js:12:45) at new Promise ( ) at scpDestinations.readDestination (/home/user/projects/norgit/node_modules/@sapmentors/cds-scp-api/lib/scp-destinations.js:11:16) at Promise (/home/user/projects/norgit/node_modules/@sapmentors/cds-scp-api/index.js:43:46) at new Promise ( ) at Object.to (/home/user/projects/norgit/node_modules/@sapmentors/cds-scp-api/index.js:21:12) at InternetAPIGetRequestwithNoAuthentication (/home/user/projects/norgit/srv/north-service.js:13:39) at Object. (/home/user/projects/norgit/srv/north-service.js:23:1)

Code

const cdsapi = require("@sapmentors/cds-scp-api");

// -----------------------------------------------------------------------------------------------------
// Calling Internet API with SCP Destination:
// HTTP method: GET 
// Destination settings:
// - Name           : Northwind
// - Proxy Type     : Internet
// - Authentication : NoAuthentication
// -----------------------------------------------------------------------------------------------------
async function InternetAPIGetRequestwithNoAuthentication() {
    const cfDestination = "Northwind";
    const service = await cdsapi.connect.to(cfDestination) //destination
    // HTTP GET request based on Axios
    return await service.run({
        url: "/Products?$top=11",       

        transformResponse: ((data) => {
            return (data)
        })
    })
}
InternetAPIGetRequestwithNoAuthentication()
    .then((data) => {
        let result = JSON.parse(data)
        console.log(result.value[0].ProductName)
    })