Flow: Create SharePoint List Text Fields Using REST API with Power Automate

When you have an existing SharePoint list or if you have created one using the method described in Create SharePoint List REST API with Power Automate, you will then want to populate it with some fields.

There are several FieldTypeKinds, at least 31 and you kind find more information on them at this link, FieldType Members.

In this post, I will cover the most commonly used FieldType in SharePoint, the "single line of text". The plan is to create 10 of these fields so below, I will walk through the steps required to carry out this task.

Here is the complete Flow:

NOTE: There are 2 REST POST calls we will make. 1 that creates the field, one that adds the new field to the default view. Using REST, when you create the new field there is still a requirement to add it to a view. For the purpose of demonstration, we will use the default "All Items" view but you amend to suit if you have a need to do so.

As detailed above, start with a button and "Manually trigger a Flow", unless of course you want to adapt this and use a recurrence, HTTP POST or whatever you suits your use case.

Next, I am initialising 2 variables that include the SharePoint Site URL and one for the list name. Again, not required, you could just add them to them in to the "Send an HTTP request to SharePoint" action but this is a little neater and can help for changes in the future.

Would you like to buy Alan a coffee?

Visit the AlanPs1 Ko-fi page

Time to create an array of the 10 fields (columns) that you require.

createArray(
string('UniqueID'), 
string('CustomerName'),
string('CustomerEmail'), 
string('ResponderEmail'),
string('Answer1'), 
string('Answer2'),
string('Answer3'), 
string('Answer4'),
string('Answer5'), 
string('NPSScore')
)

Let's now create an "Apply to each", I have named mine "Apply to each Create Each New Column String" ad I am always descriptive with my naming convention.

Now for the all important REST POST calls, starting with "Send an HTTP request to SharePoint Create List Columns".

Url

_api/web/Lists/getByTitle('@{variables('ListTitle')}')/Fields

Headers

Accept | application/json;odata=verbose

Content-Type | application/json;odata=verbose

Body

{
  "__metadata": {
    "type": "SP.FieldText"
  },
  "FieldTypeKind": 2,
  "Title": "@{items('Apply_to_each_Create_Each_New_Column_String')}",
  "Required": "false",
  "EnforceUniqueValues": "false",
  "StaticName": "@{items('Apply_to_each_Create_Each_New_Column_String')}"
}

Next, let's create "Send an HTTP request to SharePoint Add Column To View".

Url

_api/web/Lists/getByTitle('@{variables('ListTitle')}')/views/GetByTitle('All%20Items')/ViewFields/AddViewField('@{items('Apply_to_each_Create_Each_New_Column_String')}')

Headers

Accept | application/json;odata=verbose

Content-Type | application/json;odata=verbose

You will now have created Fields in the SharePoint list called "HeadwindNPS", see below for an example that shows they are in the list and also a feature of the default view called "All Items"

Thanks for reading, AlanPs1

Do you need assistance building this Flow?

 

Visit the Get Help section of the Power Automate Community