0

I'm trying to insert a new task in a standard SharePoint task list, this is my item:

var item =  {
    Title: taskTitle + " - " + subSiteName ,
    ProjectId: projectID,
    AssignedToId: {'results': [15, 17]} 
};

POSTing returns an error 400.

Failed!{"readyState":4,"responseText":"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"nl-NL\",\"value\":\"An unexpected 'StartObject' node was found when reading from the JSON reader. A 'StartArray' node was expected.\"}}}","responseJSON":{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"nl-NL","value":"An unexpected 'StartObject' node was found when reading from the JSON reader. A 'StartArray' node was expected."}}},"status":400,"statusText":"Bad Request"}

Can anyone help me? Thanks in ahead.

2 Answers 2

0

Ensure that allow multiple selections is checked

enter image description here

Also, make sure your json is as below:

var data = {
    __metadata: { "type": "SP.Data.TestListItem" },
    Title: "Some title",
    ProjectId: projectID,
    AssignedToId: { 'results': [15,17] } 
}

Full code:

var listName = 'Tasks';


var itemProperties = {
    '__metadata': { "type": "SP.Data.TasksListItem" },
    "Title": taskTitle + " - " + subSiteName ,  
    "ProjectId": projectID, 
    'AssignedToId': {"results": [15,17] }  //multi-valued User field value 
};

$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
    type: "POST",
    contentType: "application/json;odata=verbose",
    data: JSON.stringify(itemProperties),
    headers: {
        "Accept": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    success: function (data) {
        console.log(JSON.stringify(data.d));
    },
    error: function (data) {
        console.log(data.responseText);
    }
});

Reference - Create task list item with REST API

1
  • Thanks alot, it was the missing __metadata that did the trick. Thanks again. Commented Dec 20, 2016 at 11:15
0

Please try below code.

  var taskProperties = {
        '__metadata' : { 'type': 'SP.Data.TasksListItem' },
        'Title': 'Order approval',
        'AssignedToId' : { { "results": ["4", "7"] } }
    };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.