For instance, when using Postman version with Postman Interceptor, the cookies (there may be several of them) from the set-cookie response header will be most likely added [by Postman Interceptor itself] from the preceding GET call to the next POST/PUT/PATCH/DELETE call.
But, if you are like me and need to write your own code or prefer using a different
testing framework like SAP API Business Hub, this will likely not happen automatically.
The session cookie generated in a GET call is a server side cookie
(HTTP-only, secure and same site none) available in the set-cookie response header.
I recommend you grab the entire content of the GET response set-cookie header
and manually add it as your cookie header in your POST/PUT request…
as depicted in the below code snippet:
// retrieve the cookies and the x_csrf_token with any GET SCIM API call
//
var x_csrf_token_ = response.headers["x-csrf-token"];
var setcookies_ = response.headers["set-cookie"];
// Here go the headers for any POST/PUT/PATCH/DELETE SCIM API call
//
headers: {
"Authorization": 'Bearer ' + logonToken, // mandatory
//"Accept": "application/json",
"Content-Type": "application/json",
"Cookie": setcookies_, // mandatory: from the preceding GET API call
'x-sap-sac-custom-auth': 'true', // mandatory: at least with eSAC
"X-Csrf-Token" : x_csrf_token_ // mandatory: from the preceding GET API call
}
|