Integration with sap to servicenow token authentication fail

Mahesh6
Kilo Contributor

We are working on token-based integration with SAP.

SAP Team has provided the rest API for the token type is “x-csrf-token” it has generated.

We are sending the csrf token in PUT rest API but it is returning as a response is “CSRF token validation failed”.

HTTP Status : 403

Error message : Method failed: (/sap/opu/odata/SAP/ZPTG_USER_UNLOCK_SRV/UserDetailsSet(Bname='KOTI6')) with code: 403 - Forbidden username/password combo

The same web services is working in postman but not in servicneow.

Please let me know if anyone did integration with ServiceNow to SAP

 

 

7 REPLIES 7

snehalkhare
Kilo Guru

Hi,

We can try passing the session cookie received along with the csrf token value in the PUT API.

Regards,

Snehal Khare

snehalkhare
Kilo Guru

Hi, 

The CSRF token validation failed issue is resolved by sending Session cookie in the POST message along with the CSRF token.

Get the session cookie using following script:

var cookies = response.getCookies();
//for( var i=0; i < cookies.size(); i++ ){ gs.print('cookie: ' + cookies.get(i)); }

var sapsessionid ='';
var cookiesArray = (''+cookies).split(';');
//iterate through all cookies, found interesting ones
for ( var i = 0; i < cookiesArray.length; i++) {
if( cookiesArray[i].indexOf("SESSIONID") > -1) {
sapsessionid = cookiesArray[i].substring(cookiesArray[i].indexOf("SESSIONID"),cookiesArray[i].length);
}
}

 

Send the cookie in the POST call as follows along with CSRF token:

r.setRequestHeader('Cookie',sessioncookie);

 

Regards,

Snehal Khare

dsheynman
Tera Contributor

Was this ever got resolved?