cancel
Showing results for 
Search instead for 
Did you mean: 

SAP UI5 Development in local IDE

0 Kudos

Hello

I have managed to build a local workspace in VSCode and it works really good so far.

Now I have only one Problem: When I try to make a POST request via oDataModel to the SAP Backend, I get the following error:

CSRF token validation failed

I have searched in server blogs and found out, that in normal scenario it is required to first fetch the CSRF token and then add it in the POST request.

But since i am working with the oDataModel.v2 from firoi, the whole token handling is already made by this class.

I also see in the browser network protocol, that it makes first the fetch and after that the POST request.

But I still receive the same error.

Here is how I instantate my oDataModel:

getServiceModel: function (serviceName, _defaultUpdateMethod) {
 return new ODataModel("https://myserver.company.com:port/sap../Z_SRV", {
     defaultOperationMode: sap.ui.model.odata.OperationMode.Server,
     defaultBindingMode: sap.ui.model.BindingMode.OneWay,
     defaultCountMode: sap.ui.model.odata.CountMode.Request,
     defaultUpdateMethod: sap.ui.model.odata.UpdateMethod.Merge,
     earlyTokenRequest: true,
     tokenHandling: true,
     serviceUrlParams: {
     "sap-client": "200"
  }
 });
 }

Does anyone have any idea what the problem could be?

Thanks

Regards

Osman

vinibar
Participant
0 Kudos

Hi, Osman!

Could your please paste your devDependecies? I recently had this exact problem and I solve it by updating my tooling.

Hi vbarrionuevo

The problem is solved now, it turned out, that I had to set tokenHandling to false. After that, I was able to fetch data from the oDataService.

Thanks anyway

Accepted Solutions (1)

Accepted Solutions (1)

Hi guys

The problem is solved now, it turned out that I had to set the parameter tokenHandling, to false. After that I was able to fetch data from the oDataService.

new ODataModel(this.sBaseUrl + serviceName + "/", {
 tokenHandling: false
});

Thanks again

Regards

Osman

Answers (1)

Answers (1)

former_member227918
Active Contributor
0 Kudos

try oDatamodel.refreshSecurityToken() once before your POST request, it might help, or delete below two properties from your model definition, default value would be ok i.e. earlyTokenRequest is 'false' and tokenHandling is 'true'.

earlyTokenRequest: true,
tokenHandling: true,

Thanks,

Akhilesh

0 Kudos

Hi akhilesh.upadhyay

I tried what you have mentioned, but I am still receiving 403 Forbidden. When I make the same $batch POST request from Postman it works.

Thanks anyway

Osman

former_member227918
Active Contributor
0 Kudos

earlier also you were getting 403 forbidden error only? can you post request and response from network tab ?