I'm looking to bulk create items to decrease the amount of calls being made in my application. In this instance, I'm working on a calendar control that has different needs than what SharePoint OOTB provides (or allows you to modify). That said, if a user selects several days and wants to create list items for those days, it makes no sense to make separate calls per item.
However, I can't figure out the correct way to format the JSON object to send out. My call is returning the following in data.body: {\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"A node of type 'StartArray' was read from the JSON reader when trying to read the start of an entry. A 'StartObject' node was expected.\"}}}"
That error is true -- I'm pushing SharePoint objects and trying to send those out. Here is my code:
for (var i = 0; i <= diffDays; i++) {
items.push({
__metadata: { "type": "SP.Data.TestListItem" },
OData__x0066_x20: userName(),
qnlu: startDate.addDays(i),
OData__x006e_ot5: status
});
}
executor.executeAsync({
url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + LIST_NAME + "')/items?@target='" + hostweburl + "'",
method: "POST",
body: JSON.stringify(items),
headers: {
"Accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: onAddEventSuccess,
error: onoDataCallFailure
});
And here is the JSON object I'm trying to POST (taken from Visual Studio debugging): [{\"__metadata\":{\"type\":\"SP.Data.TestListItem\"},\"OData__x0066_x20\":\"user\",\"qnlu\":\"2013-07-24T04:00:00.000Z\",\"OData__x006e_ot5\":\"test\"},{\"__metadata\":{\"type\":\"SP.Data.TestListItem\"},\"OData__x0066_x20\":\"user\",\"qnlu\":\"2013-07-24T04:00:00.000Z\",\"OData__x006e_ot5\":\"test\"},{\"__metadata\":{\"type\":\"SP.Data.TestListItem\"},\"OData__x0066_x20\":\"user\",\"qnlu\":\"2013-07-24T04:00:00.000Z\",\"OData__x006e_ot5\":\"test\"}]
Any help is appreciated.