I am currently developing a SharePoint 2013 app and I have ran into an issue.
I have REST api that runs when the user tries to submit data, I have managed to get the Title field to submit the SharePoint list but I cannot get the Date Input value to submit to the list. The list is situated in the Host Web and the rest of the code does appear to work.
I am seeing a '400 (bad request)' in the console when submitting.
I currently have the following code:
function Submit() {
$('#submitBtn').click(function () {
var listName = "MyList";
var itemType = "SP.List";
var item = {
"__metadata": { "type": itemType },
"Title": $('#TitleInput').val(),
"Date": $('#DateInput').val()
};
var url = appweburl + "/_api/SP.AppContextSite(@target)" +
"/web/lists/getbytitle('" + listName + "')/items?" +
"@target='" + hostweburl + "'";
var bodyItem = JSON.stringify(item);
$.ajax({
url: url,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
console.log("Item created in host web");
},
error: function (data) {
console.log("Failed to add item to host web");
}
});
});
}
Any help would be greatly appreciated, I have had a Google on how to do this but so far turned up no reliable results.
Thanks!