cancel
Showing results for 
Search instead for 
Did you mean: 

CSRF token validation failed in SAP Cloud SDK OData Generator

NagaPrakashT
Contributor
0 Kudos

Hi Experts,

I have generated OData client for custom business object created in S/4 HANA 1909. When i am trying to create an entity using the generated class end up in following error "CSRF token validation failed". Any help?

As per the documentation the create request will fetch CSRF token before issuing the actual create request.

https://sap.github.io/cloud-sdk/docs/java/features/odata/use-typed-odata-v2-client-in-sap-cloud-sdk-...

tanvii_237
Explorer
0 Kudos

Hello Naga,

Thank you for reaching out to Cloud SDK. We are now looking into this.

Can you please provide the following information:

- The code snippet of your call

- The application and the http logs

- Which Cloud SDK version you are using ?

Regards,

Tanvi

NagaPrakashT
Contributor
0 Kudos

Hi Tanvi,

Cloud SDK - 3.28.1

Sample code snippet:

nCBOTest.setField1("SDK1");
nCBOTest.setField2("SDK2");
nCBOTest.setField3("SDK3");
final CBOTest response = service.createCBOTest(nCBOTest).execute(destination).

Thanks,

Naga

tanvii_237
Explorer
0 Kudos

Hi Naga,

Thank you for your reply.

The create request only issues a CSRF token and not validates it. Perhaps, there is another call being made to service which is trying to validate CSRF token. To verify this we have to look at the http logs and check if there are other calls being made to the service. Can you verify that or if possible provide the logs here?

Also, Instead of using setter methods on the entity object you can directly use builder object to create the java entity. See the sample code below:

final BusinessPartner businessPartner =
    BusinessPartner
        .builder()
        .firstName("firstname")
        .lastName("lastname")
        .businessPartnerCategory("1")
        .build();

Regards,

Tanvi

Accepted Solutions (0)

Answers (1)

Answers (1)

mkuhr-test
Advisor
Advisor
0 Kudos

Hi Naga, I also cannot see where the SDK would attempt any CSRF token validation. Only reason I can think of is that you are using a different version of the dependencies com.sap.cloud.servicesdk:odatav2-connectivity-sdk and com.sap.cloud.servicesdk:odata-v2-lib. The SDK uses 1.40.6.


In any case, you can replace execute with executeRequest in your code. The latter will not fail if a service does not support CSRF tokens and execute the request without a CSRF token. Also it will tell you exactly what went wrong during CSRF token retrieval if the overall request fails. You can check out the details in the release nots.