0

I am getting this error while trying to post data to SharePoint list. It has one lookup field PostCategory.

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

I have created another lookup field but there I was able to update by rest, but not able to update to the previous field.

enter image description here

PostCategory is the exisitng field and I have added Newcategory field. Both are lookup field, but there is some difference as there is no results array in NewCategory. I think may be this is the reason I am not able to post data to PostCategory field.

    $.ajax({  
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Posts')/items(1)",  
    type: "POST",  
    headers: {  
        "accept": "application/json;odata=verbose",  
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
        "content-Type": "application/json;odata=verbose",  
        "IF-MATCH": "*",  
        "X-HTTP-Method": "MERGE"  
    },  
    data: "{__metadata:{'type':'SP.Data.PostsListItem'},PostCategoryId: 4}",    
    success: function(data) {  
        console.log(data.d.results);  
    },  
    error: function(error) {  
        console.log(JSON.stringify(error));  
    }  
});  
1

If your column's internal name is PostCategory and list's internal name is Posts then try using below code as your data in POST call:

data: JSON.stringify({
        "__metadata": { type: "SP.Data.PostsListItem" },
        "PostCategoryId": 2
      })

Is multiple selection allowed on PostCategory?

Update:

For multiple selection field you need to pass the values as given below:

data: JSON.stringify({
        "__metadata": { type: "SP.Data.PostsListItem" },
        "PostCategoryId": { "results": ["2", "4"] }
      })
  • still geting the same error, multiple selection is not allowed – KumarV Jul 22 at 9:17
  • Is there any other column in list which is required and its default value is not set? – Ganesh Sanap Jul 22 at 9:34
  • Can you please add screenshot of PostCategory column settings? – Ganesh Sanap Jul 22 at 9:41
  • It seems, this PostCategory is multi selection lookup field, As i could not select more than one option in form so I thought its not a multi select field. – KumarV Jul 22 at 9:51
  • For multiple selection, please see updated answer. – Ganesh Sanap Jul 22 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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