I try adding list item using REST in SharePoint 2013. when code is try add new item in list , getting error :
"{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
"message":
{"lang":"en-US","value":"A node of type 'EndOfInput' was read from the JSON reader when trying to read the start of an entry. A 'StartObject' node was expected."}}}"
My code
var addNewTask = function() {
var data = {
__metadata: {
'type': 'SP.Data.Asana2ListItem'
},
Title: "dd",
PriorityCod: "1",
Category: "1",
Desc2: "dd",
AssignedTo: "Lynda",
CONTRACT_HDR_ID: "1"
};
//console.log(tsk.AssignedUserId);
//kkk
var hostweburl =
decodeURIComponent(
getQueryStringParameter("SPHostUrl")
);
var appweburl =
decodeURIComponent(
getQueryStringParameter("SPAppWebUrl")
);
var scriptbase = hostweburl + "/_layouts/15/";
// Load the js files and continue to the successHandler
$.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);
function execCrossDomainRequest() {
// executor: The RequestExecutor object
// Initialize the RequestExecutor with the add-in web URL.
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: appweburl +
"/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('Asana2')/items/?@target='" +
hostweburl + "'",
method: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
"content-Type": "application/json;odata=verbose"
},
"X-HTTP-Method": "POST",
"content-length": 50,
"If-Match": "*",
data: JSON.stringify(data),
success: successHandler1,
error: errorHandler1
});
}
function successHandler1(data) {
console.log(data);
}
function errorHandler1(data, errorCode, errorMessage) {
console.log(data);
}
Need help. I am new to sharepoint