SpRestLib

SpRestLib

  • Download
  • Get Started
  • API Documentation
  • SharePoint Guides
  • GitHub

›Recent Posts

Recent Posts

  • Uploading a file to a SharePoint library using JavaScript
  • Downloading a file from SharePoint library using JavaScript and REST API
  • Converting SharePoint 2010 API column names to SharePoint 2013 API column names
  • SharePoint List Unique Permissions REST Query
  • Adding a User to SharePoint Group Using REST with SpRestLib
  • Creating SharePoint jQuery People-Picker with SpRestLib
  • Creating SharePoint List Columns Using REST
  • Uploading a file to a SharePoint library using REST

Creating SharePoint List Columns Using REST

April 20, 2018

Brent Ely

List and Library fields/columns can be created using the REST API. A feature which is especially useful in many scenarios, such as having to update many subsites with new fields, doing migration work, etc.


All of the various field types can be created using REST: choice fields, date time fields, and lots of other common types.

Create a field by POST-ing to the list's /fields endpoint with a SP field definition and options.

Example: Create a new single line text field on "Accounts"

var objNewField = {
    '__metadata': {'type':'SP.FieldText'},
    'FieldTypeKind': 2,
    'Title': 'single line of text'
};

sprLib.rest({
    url : "_api/lists/getbytitle('Accounts')/fields",
    type: "POST",
    data: JSON.stringify(objNewField)
})
.then( () => console.log('Column created!') )
.catch( strErr => console.error(strErr) );

Other Field Type Objects:

// Text
var objText = {
    '__metadata': {'type':'SP.FieldText'},
    'FieldTypeKind': 2,
    'Title': 'Expense Title'
};
// Date/DateTime
var objDate = {
    '__metadata': {'type':'SP.FieldDateTime'},
    'FieldTypeKind': 4,
    'Title': 'Phase 1 Date',
    'DisplayFormat': 0 // (DateOnly = 0, DateTime = 1)
};
// Number
var objNumb = {
    '__metadata': {'type':'SP.FieldNumber'},
    'FieldTypeKind': 9,
    'Title': 'Cost Center',
    'MinimumValue': 1,
    'MaximumValue': 1000
};
// Currency
var objCurr = {
    '__metadata': {'type':'SP.FieldCurrency'},
    'FieldTypeKind': 10,
    'Title': 'Expenses Total'
};

Reference

Check the Fields REST API Reference for more types.

Tweet
Recent Posts
  • Example: Create a new single line text field on "Accounts"
  • Other Field Type Objects:
  • Reference
SpRestLib
Docs
Getting Started with SpRestLibSharePoint API ReferenceSharePoint Development GuidesAbout JavaScript Promises
Community
FacebookTwitterPinterestYouTube Channel
More
GitHub IssuesGitHub ProjectSpRestLib on Stack OverflowSite Icons
Copyright © 2019 Brent Ely