Updating Items to SharePoint List Using RESTAPI POST method.

This script Adds an item in the List of a Sharepoint site using RESTApi.

Unlike the Get method an additional metadata is to be passed which contains the List Name,its type and the value to be passed along with the Column Name.

function addListItem() {
listname = “Yahoo”;
url = “https://abc/sites/”;
metadata = “Title” + ‘:’ + “New Title”;
var test = getListItemType(listname);
var item = $.extend({
“__metadata”: { “type”: getListItemType(listname) },
“Title”: “New Title”
});
//var metadata = “{ ‘__metadata’: { ‘type’: ‘SP.Folder‘ }, ‘ServerRelativeUrl’: ‘/” + serverRelativeUrl + “‘}”
$.ajax({
url: url + “/_api/web/lists/getbytitle(‘” + listname + “‘)/items”,
type: “POST”,
processData: false,
contentType: “application/json;odata=verbose”,
data: JSON.stringify(item),
headers: {
“Accept”: “application/json;odata=verbose”
},
success: function (data) {
alertt(“Added successfully”);
},
error: function (data) {
alert(“Failed operation”);
}
});

}
$(document).ready(function () {
addListItem();
}

Advertisements

One thought on “Updating Items to SharePoint List Using RESTAPI POST method.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s