Create a column in a list using Rest API in SharePoint Online/2013/2016

This SharePoint Rest API tutorial explains, how to create a column in a list using Rest API in SharePoint Online or SharePoint 2013/2016.

Create column in list using Rest API in SharePoint Online/2013/2016

Here in this demo let us take one textbox and one button in HTML form. The user can give a column name in the textbox and click on the Submit button. Once the column created successfully it will display a successful message in the div whose id is “divResults“.

For this particular example, let us use a script editor web part inside a web part page in SharePoint. In that script editor page, you can add the HTML code as well as the rest API code.

HTML Code:

Below is the HTML code

<div>
<strong>Enter Column Name:</strong>
<input type="text" id="txtColumnName" />
<input type="button" id="btnSubmit" value="Create Column" />
</div>
<div id="divResults"></div>

Rest API Code:

Below is the rest api code to create a column in a SharePoint Online list.

Here is data, we are passing the metadata for the column like, Title for the column and also we are providing the column type by using the FieldTypeKind property. This property gets or sets a value that specifies the type of the field.

  • FieldTypeKind : 1 -> integer value
  • FieldTypeKind : 2 -> single line of text
  • FieldTypeKind : 3 -> multiple lines of text etc.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<script>
$(function () {
bindButtonClick();
});

function bindButtonClick() {
$("#btnSubmit").on("click", function () {
createColumn();
});
}

function createColumn() {
var folderName = $("#txtColumnName").val();
var siteUrl = _spPageContextInfo.webAbsoluteUrl;
var fullUrl = siteUrl + "/_api/web/lists/GetByTitle('MyCompanyInfo')/Fields";
$.ajax({
url: fullUrl,
type: "POST",
data: "{ '__metadata': { 'type': 'SP.Field' }, 'Title':'" + folderName + "', 'FieldTypeKind': 3 }",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: onQuerySucceeded,
error: onQueryFailed
});
}

function onQuerySucceeded() {
$("#divResults").html("Column Created Successfully !!!");
}

function onQueryFailed() {
alert('Error!');
}

</script>

Now when we Save the page and refresh the page, the HTML will come. Give a name for the column and click on the button, which will successfully create the column in the list.

create column in list using rest api sharepoint

Now if you can navigate to the list settings page, you can see the new column has been added to the list like below:

create column in list using rest api sharepoint online

You may like following SharePoint Rest API tutorials:

This SharePoint tutorial explained, how to create a column in SharePoint list using Rest API in SharePoint Online or SharePoint 2013/2016.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

  • […] Create a column in a list using Rest API in SharePoint Online/2013/2016 […]

  • >