Try this solution:
var destination = $.net.http.readDestination(destinationPackage,destinationName); // getCSRF Token function getCSRF() { var request; var response; try { // GET Operation on the base odata URL request = new $.web.WebRequest($.net.http.GET, "?$format=json"); // X-CSRF-Token header will be set with value Fetch request.headers.set("X-CSRF-Token", "Fetch"); client.request(request, destination); response = client.getResponse(); // reading the token from response header return response.headers.get("X-CSRF-Token").toString(); } catch (errorObj) { $.response.setBody(JSON.stringify({ ERROR: errorObj.message })); return "CSRF TOKEN FETCH FAILED : " + errorObj.message; } }↧