I'm trying to create a list item in a default SharePoint Tasks list, with a specific parent id to create a hierarchy of tasks, e.g.
Parent Task --> Child Task --> etc.
The internal property "ParentID" is what needs to be set, and via JSOM it works fine, e.g. code:
function newSubTask() {
var oList = context.get_web().get_lists().getByTitle('TaskList');
var itemCreationInfo = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(itemCreationInfo);
oListItem.set_item('Title', 'new001');
oListItem.set_item('ParentID', '1');
oListItem.update();
context.load(oListItem);
context.executeQueryAsync(Function.createDelegate(this, function (){
alert('Item created: ' + oListItem.get_id());
}), Function.createDelegate(this, function (ctx, args){
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}));
}
(Source: http://blog.csdn.net/tristan_dong/article/details/9358547)
That works as expected and the new task named "new001" is created as a child of task with ID 1.
However, I need to do this in a workflow so I need to use REST, for example using Postman in Chrome;
POST /sites/pwa/_api/Web/Lists/getbytitle('TaskList')/Items HTTP/1.1
Host: [removed].sharepoint.com
Accept: application/json; odata=verbose
Content-Type: application/json
Origin: https://[removed].sharepoint.com
X-RequestDigest: [removed]
Cache-Control: no-cache
Postman-Token: cddcccdf-3a74-0e35-a8db-740293504c4a
{ "Title": "Test from REST", "ParentID": 1 }
Returns the 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."
}
}
}
If I leave out the "ParentID" and just post a body of { "Title": "Test from REST" } it DOES work. (So my Digest and all the other stuff is working fine)
I have tried modifying the ParentID data type, any type of string or integer (primitive value) returns the above error, however an Object requested like { "Title": "Test from REST", "ProjectID": {"ID","1" }} alwaysreturns the following regardless of the contents of the object:
{
"error": {
"code": "-2147467261, System.ArgumentNullException",
"message": {
"lang": "en-US",
"value": "Value cannot be null.\r\nParameter name: entitySet"
}
}
}
What's going on? Why does it work in JSOM (or CSOM for that matter) but not in REST?