Insert using REST API

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.

<script src=””></script>

<script src=””></script>

Insert Code

Following is the Insert Code to Insert an item.

<script type=”text/javascript”>

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

Your email address will not be published. Required fields are marked *