cancel
Showing results for 
Search instead for 
Did you mean: 

How to call API endpoint on BTP nodejs app from another BTP app?

Qualiture
Active Contributor
0 Kudos

Hi all,

I have a BTP NodeJS application (A) which needs to make a REST call to another BTP application (B) at a regular interval.

In the mta.yaml file for app (A) I have specified the following resource which links to the exposed service of app (B):

  - name: app_a_using_app_b_api
    type: configuration
    parameters:
      provider-nid: mta
      provider-id: <app B name>:<app B exposed service>
      version: ">=0.0.0" 
This resource has been added as a required resource for app (A) module:
  - name: app_a_srv
    type: nodejs
    path: .
    requires:
      - name: app_a_db
      - name: app_a_using_app_b_api
        group: destinations      
        properties:
          forwardAuthToken: false
          name: app_b_api
          url: ~{url}        
          timeout: 30000
In app (A) package.json I then specified the destination: 
  "cds": {
    "requires": {
      "middlewares": true,
      "app_b_api": {
        "kind": "destination",
        "credentials": {
          "destination": "app_b_api"
        }
      }
    }
  }

Within app (A), at a regular interval, the following function is then called:

    async doRequestToAppB() {
        try {
            const destination = await getDestination({ destinationName: "app_b_api" });
            const data = await executeHttpRequest(destination, {
                method: 'GET',
                url: "/api/ping"
            });

            logger.info(`Request OK: ${JSON.stringify(data)}`);
        } catch (err) {
            logger.error(`Request FAILED: ${err}`);
        }
    }

This request now fails with the following error in the catch-clause:

[app_a] - Request FAILED: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'TLSSocket'
| property '_httpMessage' -> object with constructor 'ClientRequest'
--- property 'socket' closes the circle

I have tried many ways, but somehow I don't seem to be able to have app (A) automatically do a request to app (B), failing with the above error...

I also tried to debug the executeHttpRequest function from within BAS, but that did not give me any clues either.

If anyone has any clues, ideas, directions or tips on how to solve this, that will be highly appreciated!

Thanks in advance,

Robin van het Hof

Accepted Solutions (0)

Answers (0)