sharepoint-icon-x128

In this post I have shared the process to create a new column in SharePoint list or library using REST API or PowerShell. The process is fairly simple and straight forward.

Prerequisites

You need the following for this tutorial

  • An application to call API endpoints such as Postman, VS code or Power Automate. I have used Power Automate (If you are not familiar with Power Automate, I would request you to check my beginners tutorial for Power Automate)
  • You need to have at least edit permission in the SharePoint list (this is mandatory to create a column using any method, including REST API & PowerShell).

Implementation

#1. SharePoint REST API

The API endpoint for creating a column is

 POST https://{site_url}/_api/web/lists(guid'{list_guid}')/Fields

As this is a creation request, a POST method is required. Also you need few headers and a request body. The request body contains the information about the new column you are trying to create. Such as column name, type, hidden etc. An example is shown in the below picture and the respective explanation is provided below.

REST API to create a column from Power Automate
Explanation below

As you can see in the above image, it is a simple POST API call to create a new column. A few parameters are passed in the content body with the column related information(explanation for each are below).

I have used the numbers(as per the image) to explain the details below.

  1. URI – The Uri is mentioned above.
    A list guid is a unique identifier which can be found from the SharePoint list settings or by calling the list API( _api/web/lists/getbytitle(‘Title’) ) .
  2. Headers – headers carry validation, authentication or related information.
    If you are calling the API from Power Automate (or a JS script within SharePoint) then you require only these two headers as shown in the above image. However if you are using any other applications such as Postman or VS code then you would need other headers such as accesstoken. More information regarding those can be found on the Microsoft documentation, however if you need any tutorial let me know in the comments.
  3. The type metadata SP.Field identifies that the POST request body is for a SharePoint Field(column)
  4. Title: The title you would like to show in the SharePoint list view
  5. FieldTypeKind: This is a numerical value which identifies the type of column(i.e. Text, number, hyperlink etc.). More information on this is provided below. However if you do not want to use the numerical value then, you can use the property TypeAsString.
  6. Required: Whether this column is mandatory to fill or not
  7. EnforceUniqueValues: Whether the information provided in this column should be unique or not
  8. staticname: static name of the column/field
  9. Hidden: Whether the field is hidden in the default view.

Details of the API

Header

 Accept: "application/json;odata=verbose"
 Content-Type: "application/json"

Body

 {
  "__metadata": {
    "type": "SP.Field"
  },
  "Title": "field title",
  "FieldTypeKind": 2,
  "Required": "true",
  "EnforceUniqueValues": "false",
  "StaticName": "field name",
  "Hidden":"false"
 }

Final Result

The above request should be enough to create a/multiple column in SharePoint using REST API. And if you call the API correctly with the above details, a column should be created as below. The column should show an error “Required information missing” and it should be visible in the default view.

Column created using SharePoint REST API Power Automate
Column in SharePoint view
SharePoint REST API Power Automate to create column
Column properties

Additional information

If you have followed along then you should have at least two questions in your mind. They are

  • What are the available values for FieldTypeKind (i.e. how to create other column types) ?
  • And, is it possible to pass more parameters in the request body? For example description, default value etc.

Well, good news! I have both the answers for you below.

Q. What are the different field type values available ?

You can create every kind of available field types, using both REST API and PowerShell. Below is a table with some most commonly used FieldTypeKind values for SharePoint REST API. For all available FieldTypeKind values follow Microsoft documentation. You can use these values from the table to create different kinds of columns.

*Note – You should not use any invalid FieldTypeKind value in SharePoint REST API. It can cause issues
Column TypeValueDescription
Integer1Specifies that the field contains an integer value. 
Text2Specifies that the field contains a single line of text.
Note3Specifies that the field contains multiple lines of text. 
DateTime4Specifies that the field contains a date and time value or a date-only value.
Counter5Specifies that the field contains a monotonically increasing integer.
Choice6Specifies that the field contains a single value from a set of specified values.
Lookup7Specifies that the field is a lookup field. 
Boolean8Specifies that the field contains a Boolean value. 
Number9Specifies that the field contains a floating-point number value. 
Currency10Specifies that the field contains a currency value. 
URL11Specifies that the field contains a URI and an optional description of the URI. 
Computed12Specifies that the field is a computed field.
Guid14Specifies that the field contains a GUID value. 
MultiChoice15Specifies that the field contains one or more values from a set of specified values. 
Calculated17Specifies that the field is a calculated field. 
File18Specifies that the field contains the leaf name of a document as a value.
Attachments19Specifies that the field indicates whether the list item has attachments. 
User20Specifies that the field contains one or more users and groups as values. 
Recurrence21Specifies that the field indicates whether a meeting in a calendar list recurs. 
Error24Specifies that the type of the field was set to an invalid value.
ContentTypeId25Specifies that the field contains a content type identifier as a value.
WorkflowStatus28Specifies that the field indicates the status of a workflow instance on a list item.
AllDayEvent29Specifies that the field indicates whether a meeting in a calendar list is an all-day event.
WorkflowEventType30Specifies that the field contains the most recent event in a workflow instance.

Q. Different properties available for SP.Field POST request body

Similar to the above table, below is a table with the most commonly used properties/parameters for SP.Field body. For full list of parameters, check the Microsoft document.

PropertyTypeRead/WriteDescription
CanBeDeletedBooleanRGets a value that specifies whether the field can be deleted.
DefaultValueStringR/WGets or sets a value that specifies the default value for the field.
DescriptionStringR/WGets or sets a value that specifies the description of the field.
DirectionStringR/WGets or sets a value that specifies the reading order of the field.
EnforceUniqueValuesBooleanR/WGets or sets a value that specifies whether to require unique field values in a list or library column.
FieldTypeKindInt32R/WGets or sets a value that specifies the type of the field. Represents a Field Type value. See FieldType in the .NET client object model reference for a list of field type values
FilterableBooleanRGets a value that specifies whether list items in the list can be filtered by the field value.
GroupStringR/WGets or sets a value that specifies the field group.
HiddenBooleanR/WGets or sets a value that specifies whether the field is hidden in list views and list forms.
IdGUIDRGets a value that specifies the field identifier.
IndexedBooleanR/WGets or sets a Boolean value that specifies whether the field is indexed.
InternalNameStringRGets a value that specifies the field internal name.
ReadOnlyFieldBooleanR/WGets or sets a value that specifies whether the value of the field is read-only.
RequiredBooleanR/WGets or sets a value that specifies whether the field requires a value.
SchemaXmlStringR/WGets or sets a value that specifies the XML schema that defines the field.
ScopeStringR/WGets a value that specifies the server-relative URL of the list or the site to which the field belongs.
SealedBooleanR/WGets a value that specifies whether properties on the field cannot be changed and whether the field cannot be deleted.
SortableBooleanR/WGets a value that specifies whether list items in the list can be sorted by the field value.
StaticNameStringR/WGets or sets a value that specifies a customizable identifier of the field.
TitleStringR/WGets or sets value that specifies the display name of the field.
TypeAsStringStringR/WGets or sets a value that specifies the type of the field.
ValidationFormulaStringR/WGets or sets a value that specifies the data validation criteria for the value of the field.
ValidationMessageStringR/WGets or sets a value that specifies the error message returned when data validation fails for the field.

That’s all you need to create a column using REST API in SharePoint Online. Next let’s check the PowerShell option

#2. Create SharePoint column using PowerShell

There are already many documents available online and as I do not wish to increase the document length, I have included the link of those documents instead of rewriting them again. If you have any questions feel free to ask in the comments.

https://www.sharepointdiary.com/2016/12/sharepoint-online-create-site-column-using-powershell.html

https://www.c-sharpcorner.com/blogs/create-a-site-column-using-powershell-in-sharepoint1

That’s all I have for this document, create a SharePoint column using REST API and PowerShell. And I hope this to help you in your requirement.

Please Help us Grow!

I hope you have found this article helpful. If you are happy with the document, please use the below links when you buy something from Amazon to help us grow.

How this works?

Amazon affiliate program gives a small (%)share of price to the referrers, so feel free to buy anything.
Below are some Amazon affiliate links, if you open amazon application/website using these links and buy something, (it can be one of the below items or anything of your choice) Then Amazon will give us a little percentage(%) of the money you spend on Amazon. To know more check this document.

Amazon Affiliate Links

$350-Best Student laptop
Amazon In, Amazon US

$600-Work laptop
Amazon In, Amazon US

$989– High performance
Amazon In, Amazon US

Headset – $15.99
Amazon In, Amazon US

Lightspeed Mouse – $39
Amazon In, Amazon US

Keyboard – $29
Amazon In, Amazon US

The Psychology of Money
Amazon In, Amazon

Atomic Habits:
Amazon In, Amazon

Find Balance and Purpose in Life
Amazon In, Amazon

$30, Smart Watch for Smart you
Amazon In, Amazon US, Amazon UK

Work comfortably with $110
Amazon In, Amazon US, Amazon UK

Exercise at home
Amazon In, Amazon US, Amazon UK

More Ways to Help

Thank you
For your Contribution


Newbietechie.com
Author @ramizmollahmd

About Ramiz

Ramiz is a professional working in an MNC as a business and technology consultant for quite a few years now. Ramiz is proficient in various Microsoft tools and technologies. He is a tech enthusiast and an active blogger. Ramiz spends his free time playing games or watching movies. He writes blogs to share his knowledge with the world and to make it a better place to live.


Leave a Comment