I am trying to use request to create a SharePoint list with node. I am 90% sure all my headers are okay, but I am not too sure. I know all the auth headers are populated with values too; any help would be.
var inputJSON = {
"Connection": {
"SiteUrl": "na",
"Tennent": "na",
"Username": "na",
"Password": "na"
},
"Request": {
"Title": "Test List",
"TemplateType": "100",
"Description": "My test list description"
}
};
var Toptions = {
auth: {
username: inputJSON.Connection.Username,
password: inputJSON.Connection.Password
},
host: inputJSON.Connection.Tennent
};
var Sharepoint = require('sharepoint-auth');
Sharepoint(Toptions, function (err, result) {
if (err) {
console.log(err);
} else {
var requestOptions = {
url: inputJSON.Connection.SiteUrl + '_api/web/lists',
method: 'POST',
body: {
'__metadata': {
'type': 'SP.List'
},
'AllowContentTypes': true,
'BaseTemplate': 100,
'ContentTypesEnabled': true,
'Description': 'My list description',
'Title': 'MY TEST LIST'
},
headers: {
'Accept': 'application/json;odata=verbose',
'Content-type': 'application/json;odata=verbose',
'Cookie': 'FedAuth=' + result.cookies.FedAuth + ';rtFa=' + result.cookies.rtFa + ';',
'X-RequestDigest': result.requestDigest,
'Authorization': 'Bearer ' + result.accessToken,
'content-length': 255
},
json: true
};
var request = require('request');
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(response);
} else {
console.log(error);
}
}
request(requestOptions, callback);
}
});