Can anyone explain or point me to a link with samples of doing Update, Delete using Jquery with the SharePoint 2010 Rest API?
I have the insert working and of course queries since the MSDN documentation explains and every tutorial on the net explains queries but just wondering if anyone ever inserts, updates, deletes data instead of only samples and tutorials on querying? Yes I know I can use the CSOM but I want to learn how this is done via jquery and sharepoint rest?
Also I want to use Merge for updating.
Here's the working insert code:
function insertMilestone() {
var mileStonesListUrl = "/_vti_bin/listdata.svc/Milestones";
var milestone = {};
milestone.Title = "Testing from REST";
var entry = JSON.stringify(milestone);
$.ajax({
type: "POST",
url: mileStonesListUrl,
data: entry,
contentType: "application/json; charset=utf-8",
error: function (xhr) {
alert(xhr.status + ": " + xhr.statusText);
},
success: function () {
getAll();
}
});
}
How to perform CRUD operations using SharePoint 2010 REST Interface
Create
In order to perform a Create operation via REST, you must perform the following actions:
POST
verb.application/json
.JavaScript example:
Usage
Read
In order to perform a Read operation via REST, you must perform the following actions:
application/json
.JavaScript example:
Usage
Update
To update an existing entity, you must perform the following actions:
HTTP
request using thePOST
verb.X-HTTP-Method
header with a value ofMERGE
.POST
If-Match
header with a value of the entity’s original ETag.JavaScript example:
Usage
Delete
To delete an entity, you must perform the following actions:
POST
verb.X-HTTP-Method
header with a value ofDELETE
.If-Match
header with a value of the entity’s original ETag.JavaScript example:
Usage
Please follow List Items manipulation via REST API in SharePoint 2010 article for a more details.
I recently worked with the REST API for SP 2013, as a Example POC that can be used for any call implementation i.e. JQuery, C# etc.
Using POSTMAN
First get your digest token:
A method was found on this site : http://tech.bool.se/basic-rest-request-sharepoint-using-postman/ [Credit where credit is due]
POST
Header:
Body: Clear the body
From the payload use "FormDigestValue" value and put it into your headers with the key : X-RequestDigest when making actions that alter items in SharePoint.
Reading data:
GET
Headers:
When it comes to create, update , delete you need the digest token or an authorization token to perform these actions, this token is highlighted at the begining to to retrieve.
Creating Data POST
Headers:
Body:
Note: 'ServerRelativeUrl' the folder on the end POC3 is the folder that I want to create
Related resources: http://msdn.microsoft.com/en-us/library/office/fp142380(v=office.15).aspx
Note: PostMan was used for this example and other application may need you to url encode the endpoint.
The above Request Structure can be used for all requests, the related resource highlights some of the standard methods that can be used with the REST Api
Here is the update and delete, it wasn't as hard as I thought it was going to be and it works. Hopefully this will help someone out because there is so much bogus information on using the REST API and I see a zillion posts on querying but none on Insert, Update, Delete.