Creating a new task in SharePoint list using CSOM/Rest API
var fieldUserValues = new Array();
fieldUserValues.push(userId); //userid is ID of user
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Project Tasks')/Items",
type: 'POST',
async: false,
headers: {
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "POST"
},
data: JSON.stringify({
__metadata: {
type: "SP.Data.Project_x0020_TasksListItem"
},
Title: taskName,
StartDate: taskStartDate,
DueDate: taskDueDate,
PercentComplete: percentageComplete, //percentage complete should be integer
AssignedToId: { "results": fieldUserValues }
}),
success: function(data) {
alert('Item created successfully!');
},
error: function(error) {
alert(JSON.stringify(error));
}
});