As explained in the official Sitecore documentation, I'm using the following block of code to login into the Sitecore.
module.exports = function (context, req) {
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
/*context.log('ReadyState='+this.readyState);
if(this.readyState === 4 && this.status === 200) {
context.log('Response='+this.responseText);
}*/
};
xhr.open("POST", "https://content-XXXXX.com/sitecore/api/ssc/auth/login",true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send('{"domain":"sitecore","username":"XXXXX","password":"XXXXXX"}');
context.done();
};
The request sends back a token to inform the authentication succeeded, but the documentation does not explain how to use it to send another POST request, for example to creating an item in the content tree. How should I use it ?
xhr2.open("POST", "https://content-XXXXXXXXX/sitecore/api/ssc/item/sitecore%2Fcontent%2Fhome",true);
xhr2.setRequestHeader("Content-Type", "application/json"); <-- TOKEN HERE ?
xhr2.send('{"ItemName": "MyTest","TemplateID":"XXXXXXXXX","Title":"Sitecore","Text":"MyTestText"}');
Thank you in advance for your help