Hi Swetha,
the above example is exactly doing this!
You can get a CSRF via
function getCSRFToken(dest, client){
var req = new $.web.WebRequest(
$.net.http.HEAD,
"/sap/opu/odata/iwfnd/catalogservice"
);
req.headers.set("x-csrf-token", "fetch");
client.request(req, dest);
var response = client.getResponse();
var CSRF = response.headers.get("x-csrf-token");
if (response.status===200) {}
else {
//handleErrors(response);
}
return CSRF;
}
a HEAD call will be enough (less footprint than GET because you only need the token).
Then you can call the needed OData service (or in my case directly the RFC)
var req = new $.web.WebRequest(
$.net.http.POST,
"/sap/gw/jsonrpc"
);
req.contentType = "application/json";
req.headers.set("x-csrf-token", CSRF);
// put your ODATA payload here instead RFC
var requestData = {
"jsonrpc": "2.0",
"method": sMethod,
"params": oParameters,
"id": 1
};
Regards,
Holger