Skip to Content
0
Jul 06 at 11:12 PM

External service in multitenant app

30 Views Last edit Jul 07 at 03:20 PM 2 rev

Hi everyone. I added the logic for consuming the NorthWind service. It works when the credentials are in the package.json file like "NorthWind": { "kind": "odata", "model": "srv/external/NorthWind", "credentials": { "url": "https://services.odata.org/Experimental/OData/OData.svc" }. When I change it for destination it stops working. I have destinations created in the BTP for the application and also I created with the same name for the tenant. I get the error "Bad Gateway".

Tenant desctination

package.json
            "NorthWind": {
                "kind": "odata",
                "model": "srv/external/NorthWind",
                "credentials": {
                    "destination": "NorthWind"
                }
            }
service.cds

using {NorthWind as external1} from './external/NorthWind.csn';

service CatalogBYD @(path : '/catalog')
 {
    @readonly
    entity Products as projection on external1.Products {
        key ID, Name, Description, ReleaseDate, DiscontinuedDate, Rating, Price
    };
}


service.js

const cds = require('@sap/cds');

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

log

.................
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR               accept: [ 'Accept', 'application/json' ],
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR               'content-type': [ 'Content-Type', 'application/x-www-form-urlencoded' ],
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR               authorization: [
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR                 'Authorization',
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR                 'Basic c2I0MYzcmd05jZXE0NU09'
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR               ],
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR               'user-agent': [ 'User-Agent', 'axios/0.21.1' ],
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR               'content-length': [ 'Content-Length', 29 ],
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR               host: [
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR                 'Host',
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR                 .authentication.eu10.hana.ondemand.com'
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR               ]
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR             }
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR           },
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR           data: {
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR             error: 'unauthorized',
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR             error_description: 'Bad credentials'
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR           }
   2021-07-06T23:03:01.08+0000 [APP/PROC/WEB/0] ERR         },
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR         isAxiosError: true,
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR         toJSON: [Function: toJSON]
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR       }
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR     }
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR   },
    2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR   correlationId: 'ac34c59e-1123-4c90-98ee-cb163005eabd'
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR }
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR [cds] - Error: Error during request to remote service: Failed to build HTTP request for destination: failed to load destination!
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR     at run (/home/vcap/deps/0/node_modules/@sap/cds-runtime/lib/remote/utils/client.js:209:25)
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR     at processTicksAndRejections (internal/process/task_queues.js:97:5) {
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR   code: 502,
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR   id: '1318776',
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR   level: 'ERROR',
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR   timestamp: 1625612559625
   2021-07-06T23:03:01.09+0000 [APP/PROC/WEB/0] ERR }

Attachments

mainaccount.png (10.4 kB)
tenant.png (10.2 kB)