How do I create a new list item for a list that has a user lookup field? I have seen other people pass the ID of the user, but that isn't working for me. I get a 400 error when I try that.
I have added Id to the end of the field name as shown below, which other threads say is required.
Here's what I have been trying -
var data = {
__metadata: { 'type': 'SP.Data.ProjectsListItem' },
Title: '' + name + '',
Start_x0020_Date: new Date(start).toISOString(),
End_x0020_Date: new Date(end).toISOString(),
Project_x0020_ManagerId: 441,
Additional_x0020_Details: note
};
$.ajax({
url: siteURL + "/_api/web/lists/getbytitle('Projects')/items",
method: "POST",
contentType: 'application/json;odata=verbose',
data: JSON.stringify(data),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function(data) {
alert('Item added successfully');
},
error: function(error) {
alert(JSON.stringify(data));
}
});