4

How can I save document library lookup field using REST API Post in a SharePoint list? I tried like

'docItem':'1;#test'

But, it is throwing an error :

{
  "error": {
    "code": "-1,Microsoft.SharePoint.Client.InvalidClientQueryException",
    "message": {
      "lang": "en-US",
      "value": "A 'PrimitiveValue' node with non - null value was found when trying to read the value of a navigation property;however, a 'StartArray' node, a 'StartObject' node, or a 'PrimitiveValue' node with null value was expected."
    }
  }
}

Bad Request

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Praveen Prasannan
  • 7,093
  • 10
  • 50
  • 70

3 Answers3

13

Assuming the lookup field name is docItem simply using

'docItemId':1

will do the trick.

Aleksi Niiranen
  • 348
  • 3
  • 7
0

Check any of list column name match with any predefined column name in share point,if so change that column name.For me I have a Author column (people and group datatype we have /Author navigation) in list that troubled me so I changed that name to AuthorName and its started working then.

user1487912
  • 51
  • 1
  • 1
-2

Yes please save it like below:

where Model is ng-model.

ctrlSub is controller.

data = {'FieldId' :ctrlSub.Model.Id.toString()}
Amay Kulkarni
  • 828
  • 13
  • 16
  • In mentioning Controllers and Models, this would be for a C# .NET MVC instance. You also wouldn't want to send the ID to string, but let it stay as `int`. The OP was asking about the REST API, which, from the error, is using JavaScript. – vapcguy Aug 14 '19 at 17:43