Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add ListItem to List Folder using Rest-Api

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

like image 245
Mark Avatar asked Mar 04 '14 14:03

Mark


People also ask

How do I add a folder to a SharePoint library using REST API?

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.

What is Requestdigest in REST API?

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.


1 Answers

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.

like image 97
Riaz Gaffar Avatar answered Oct 02 '22 01:10

Riaz Gaffar