Code:
function createListItem() {
var item = {
"__metadata": { "type": "SP.Data.listnameListItem" },
"Title": "testsetsetset",
"Column1": "Test",
"Column2": "Test" ,
} ;
$.ajax({
url: apphostweb + "/_api/web/lists/getbytitle('" + listname + "')/items",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
alert("Successful");
},
error: function (data) {
alert("Failure");
}
});
}
I can insert the title to the list, but after I added the column1 and column2 field in the request. There is a error:
{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"A type named 'SP.Data.listnameListItem' could not be resolved by the model. When a model is available, each type name must resolve to a valid type."}}}
Can we create whole item using this method? OR another method should be used?