cancel
Showing results for 
Search instead for 
Did you mean: 

CSRF token validation failed

0 Kudos

Hello Experts,

I am building an interface to post an attachment to S/4HANA using API_CV_ATTACHMENT_SRV entity. I am passing all the required headers to this entity but still I am getting CSRF token validation failed error. Please find below screenshot for your reference. Request you to please suggest a workaround for the stated issue.

Below groovy script used to pass Cookie header

import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.xml.*;
import java.io.*;
 
def Message processData(Message message) 
{
    def headers = message.getHeaders();
    def cookie = headers.get("set-cookie");
     message.setHeader("Cookie", cookie);
    return message;
}

Accepted Solutions (0)

Answers (4)

Answers (4)

Hi varun_vichare_cpi,

Could you please check if you have set HTTP Session Reuse property either on Exchange level or Integration flow level.

find below the screenshot as below.

Hope this helps !

thanks and regards,

Praveen T

0 Kudos

Hi Praveen,

I tried keeping HTTP session reuse both on Exchange and Integration flow level, but still getting the same error.

Regards,

Varun Vichare.

jdavanzo
Explorer
0 Kudos

Hi Varun,

did you manage to solve the problem?

I am having the same issue using the HTTP channel to update data in S/4HANA.

Unfortunately I cannot use the oData receiver adapter because the service I am using does not support navigation.

Regards,

John

former_member696122
Discoverer
0 Kudos

Hi Varun,

Are you passing token value to Header? I see you are passing the text vale 'x-csrf-token' as Token value. But ideally you need to get the Token value from S4 and pass the same during your call.

Thanks

Srini

0 Kudos

Hi Srinivas,

I am using the API mentioned in below screenshot to fetch the token value.

Regards,

Varun Vichare.

0 Kudos

Hi varun_vichare_cpi,

Could you share the details of the error.

Could you enable trace and check if the x-csrf-token value is set.

In addition could you check if you are able to make calls using POSTMAN.

thanks and regards,

Praveen T

0 Kudos

Hi Praveen,

PFB screenshot for error details and attached file for set headers. I am able to make calls to the API successfully though postman.

messagelog-attachment-api-attachment-1-http-receiv.txt

Regards,

Varun Vichare.