I have a problem with adding a ListItem in a specified Folder while using SharePoint 2013 REST api.
With the Client Object Model it would look like this:
var creationInfo = new SP.ListItemCreationInformation();
creationInfo.FolderUrl = "/Lists/MyList/MyFolder";
var item = list.addItem(creationInfo );
item.update();
ctx.executeQueryAsync(
Function.createDelegate(this, onSuccess),
Function.createDelegate(this, onFail));
But when i'm trying to set the FolderUrl via the Rest Service
{ '__metadata' : { 'type': 'SP.Data.MyListListItem' }, 'Title': 'NewItemInFolder', 'FolderUrl': '/sites/example/Lists/MyList/MyFolder' }
I got an 400 Bad Request
I have also tried to first add a ListItem to the List and then update the FolderUrl but this also didn't work.
How can I add ListItem's to a List Folder in SharePoint using the Rest-Api ?
Edit:
{ '__metadata' : {
'type': 'SP.Data.MyListListItem',
'type': 'SP.Data.ListItemCreationInformation'
},
'Title': 'NewItemInFolder',
'FolderUrl': '/sites/example/Lists/MyList/MyFolder'
}
I have now tried to use both ListItemEntityTypeFullName
the Entity from my List and the ListItemCreationInformation but I also only get a 400 Bad Request.
And when i'm looking into the request with Fiddler I see that SharePoint is ignoring now my List Entity Type SP.Data.MyListItem
In this example, we have created an HTML form which has a textbox and a submit button. The user can give a folder name in the textbox and click on submit. On successful creation of the folder inside the document library, it will show a successful message.
Request digest is a client side “token” to validate posts back to SharePoint to prevent attacks where the user might be tricked into posting data back to the server. The token is unique to a user and a site and is only valid for a (configurable) limited time.
You should not use the REST api but instead use the listdata.svc
url: /_vti_bin/listdata.svc/[Name of List]
Header:Content-Type: application/json;odata=verbose
Body: {Title: "Title", Path: "/ServerRelativeUrl"}
I had the same problem but with REST api it won't work with the old svc it will.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With