Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand

Insert using REST API

Posted by Jean Paul on January 23, 2016

In this article we can explore a simple code to Insert an Item using REST API.

Contacts List

Create a Contacts List for our purpose.


Script Inclusion

Following are the script files you need to include:

1. JQuery

2. JSON2

You can copy the following script code with Microsoft & Yandex CDN links.

Insert Code

Following is the Insert Code to Insert an item.

function test()


CreateListItemWithDetails(“Contacts”, _spPageContextInfo.webAbsoluteUrl, “New Contact”, success, failure);


function success()




function failure()




function CreateListItemWithDetails(listName, webUrl, newItemTitle, success, failure) {

var itemType = “SP.Data.” + listName + “ListItem”;

var item = {

“__metadata”: { “type”: itemType },

“Title”: newItemTitle



url: _spPageContextInfo.siteAbsoluteUrl + “/_api/web/lists/getbytitle(‘” + listName + “‘)/items”,

type: “POST”,

contentType: “application/json;odata=verbose”,

data: JSON.stringify(item),

headers: {

“Accept”: “application/json;odata=verbose”,

“X-RequestDigest”: $(“#__REQUESTDIGEST”).val()


success: function (data) {



error: function (data) {





Invoke Code

Following would be the Invoke Code.

<input type=”button” value=”Click Me..” onclick=”javascript:test();”

Testing Code

You can use a new page & Content Editor web part to test the above code. On successful insert you should be getting the message below.


You can also verify the new item in the Contacts list.


This concludes Insertion using REST API code.



In this post we have explored how to Insert an Item using REST API.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s