on 2022 Mar 02 3:02 PM
I have a REST endpoint in an on-premise system which accepts POST request to create a project. The request looks as follows.
POST https://bdt-solutions-sandbox-ugkcpmuc-sandbox-dtv-service-cf-srv.cfapps.sap.hana.ondemand.com/dtv/c...
Content-Type: application/json
{
"EXT_ID": "BDT_PROJECT2",
"NAME": "BDT Project 2"
}
This is the result if I run the request (with CSRF token fetched beforehand via GET) in Postman.
[
{
"CLIENT": "",
"ID": 559,
"UUID": "NokfYuk+xB/hAAAACu8+5g==",
"EXT_ID": "BDT_PROJECT2",
"NAME": "BDT Project2",
"NAMESPACE": "",
"PROJ_MODE": "",
"DEFAULT_PROJ": null,
"VERSION_NUMBER": "",
"EXECUTION_STATUS": "",
"LIFECYCLE_STATUS": "01",
"DATE_FORMAT": "",
"TIME_FORMAT": "",
"DECIMAL_NOTATION": "",
"CREATED_BY": "GUTKNECHTS",
"CREATED_ON": 20220302145554,
"CHANGED_BY": "GUTKNECHTS",
"CHANGED_ON": 20220302145554
}
]
In CAP, I have setup a service model with an unbound action to run the POST request.
service DTVService {
...
action createProject(EXT_ID : String, NAME : String ) returns {
CLIENT: String;
ID: Integer;
UUID: String;
EXT_ID: String;
NAME: String;
NAMESPACE: String;
PROJ_MODE: String;
DEFAULT_PROJ: Boolean;
VERSION_NUMBER: String;
EXECUTION_STATUS: String;
LIFECYCLE_STATUS: String;
DATE_FORMAT: String;
TIME_FORMAT: String;
DECIMAL_NOTATION: String;
CREATED_BY: String;
CREATED_ON: Timestamp;
CHANGED_BY: String;
CHANGED_ON: Timestamp;
}
}
In the service implementation, I am executing the request with this coding. I am currently just using fixed parameters for the request to cancel out any issue with the parameter handover.
const cds = require("@sap/cds")
class DTVService extends cds.ApplicationService {
init() {
...
this.on("createProject", async (req) => {
const dtvapi = await cds.connect.to("dtvapi")
return dtvapi.post("/createproject", {EXT_ID:"BDT_PROJECT3", NAME:"BDT Project 3"})
})
}
}
module.exports = { DTVService }
However, the result after deploying the application (locally I do not get it to run) is a HTTP error 502 with "Bad Gateway". Any idea why this happens?
Request clarification before answering.
You can use sap-cf-proxy or develop in BAS if you want to test it without deployment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 18 | |
| 7 | |
| 6 | |
| 6 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.