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.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

Bhawana Rathore

Hello Everyone!! I am Bhawana a SharePoint MVP and having about 8+ years of SharePoint experience as well as in .Net technologies . I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools . Now exploring more in SharePoint 2016 :) Hope here I can contribute and share my knowledge to the fullest. As I believe "There is no wealth like knowledge, and no poverty like ignorance"

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

  • >