‎2021 Nov 23 11:39 AM - edited ‎2024 Feb 04 2:26 AM
Hi,
I am following the learning journey 'Developing with SAP Extension Suite' from SAP BTP Learning Group. I am consuming Business Partner service from S4HANA Cloud via API Gateway sandbox. According to the learning journey, I am implementing my own service handler to handle $expand case when it calls data from business partners. However, I am getting error in cds watch logs that 'TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))'.
Here is my code
const cds = require("@sap/cds");
// service implementation with handlers
module.exports = cds.service.impl(async function () {
const { Risks, BusinessPartners } = this.entities;
// connect to remote service
const BPSrv = await cds.connect.to("API_BUSINESS_PARTNER");
// to handle $expand=bp call
this.on("READ", Risks, async (req, next) => {
try {
const res = await next();
if (Array.isArray(res)) {
const aColumns = req.query.SELECT.columns || [];
const aBpColumn = aColumns.find((column) => column.ref.includes("bp"));
if (aBpColumn.expand && aBpColumn.expand.length > 0) {
// $expand=bp was used
const aRiskBps = res.map((risk) => risk.bp_BusinessPartner);
const aBps = await BPSrv.run({
query: SELECT.from(BusinessPartners)
.where({ BusinessPartner: { in: aRiskBps } })
.columns(["BusinessPartner", "FirstName", "LastName"]),
headers: {
apiKey: process.env.apiKey,
},
});
console.log(aBps);
}
}
} catch (error) {
console.error(error);
}
});
});
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
Hi ekansh005 ,
"BPSrv.run" is not designed to provide custom headers for a request to a remote service.
Did you see that snippet in the learning journey or in one of our samples?
Please either use .send in order to send custom headers with the request or consider adding the apiKey as a declarative header to the app defined destination.
Hope that helps,
Johannes
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.