Skip to Content

CSRF token validation failed in SAP Cloud SDK OData Generator

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-for-java

Add a comment
10|10000 characters needed characters exceeded

  • 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

  • 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

  • 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

Assigned Tags

Related questions

0 Answers

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.