cancel
Showing results for 
Search instead for 
Did you mean: 

reading external (OData) API from cap

04-23-2024 8:29 AM
4889 views 7 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

Hello All,

I have a requirement to read the data from the external sap odata service from the s4hana system. but, getting below error.

SAP destination is already Basic authorization.

Error during request to remote service: Received content type 'text/html' which is not part of accepted content types

Regards,

Pragnesh

Node.js SAP Cloud Application Programming Model

0 Likes
View Entire Topic
pragnesh_parmar
Explorer
0 Likes

Hello @MioYasutake  @rileyrainey @arley-triana-morin ,

Please find below my code and let me know where errors come up.

ProCat.cds

using { ZPR_HIRED_PLANT_PO_DETAILS_SRV } from './external/ZPR_HIRED_PLANT_PO_DETAILS_SRV';
service ProCat {
   entity PurchaseorderList as projection on ZPR_HIRED_PLANT_PO_DETAILS_SRV.PO_HEADERSet;
}
ProCat.js
const cds = require("@sap/cds");
const { ConnectBackend } = require('./lib/ConnectionHandler');

module.exports = cds.service.impl(async function () {
  const { PurchaseorderList } = this.entities;
  this.on("READ", PurchaseorderList, ConnectBackend)
 
});
Backend connection I have made one different connection handler.
ConnectionHandler.js
const cds = require("@sap/cds");
async function ConnectBackend(req,res)
{
    const backendconnect = await cds.connect.to("ZPR_HIRED_PLANT_PO_DETAILS_SRV");
    const tx = backendconnect.tx(req.query);
    return tx.run(req.query);
}
module.exports = {
    ConnectBackend
}
Package.json
 "cds": {
    "requires": {
      "ZPR_HIRED_PLANT_PO_DETAILS_SRV": {
        "kind": "odata-v2",
        "model": "srv/external/ZPR_HIRED_PLANT_PO_DETAILS_SRV",
        "credentials": {
          "destination": "capsap",
          "path": "/sap/opu/odata/sap/ZPR_HIRED_PLANT_PO_DETAILS_SRV"
        }
      }
    }
  }
.env file to bypass the proxy for SAP BAS
destinations=[{"name":"capsap","proxyHost":"http://127.0.0.1","proxyPort":"8887","url":"http://capsap.dest"}]
 
 
 
I have also attached the screenshot of the BAS Error and browser error with network trace and odata call response with out cap.
 
Please help me to close this issue.
 
Regards,
Pragnesh 
 

 

pragnesh_parmar
Explorer
0 Likes
it is working now thanks 🙂
rileyrainey
Product and Topic Expert
Product and Topic Expert
0 Likes
If you don't mind, please elaborate on what fixed your issue -- it will likely help others in the future.
AnjalyMadhu
Newcomer
0 Likes

@pragnesh_parmar  Could you pls elaborate how you fixed this issue?