cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

POST request to REST endpoint in on-premise system fails with "502: Bad Gateway"

0 Kudos
499

I have a REST endpoint in an on-premise system which accepts POST request to create a project. The request looks as follows.

https://bdt-solutions-sandbox-ugkcpmuc-sandbox-dtv-service-cf-srv.cfapps.sap.hana.ondemand.com/dtv/c...

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?

Accepted Solutions (0)

Answers (1)

Answers (1)

gregorw
SAP Mentor
SAP Mentor

You can use sap-cf-proxy or develop in BAS if you want to test it without deployment.