Create a SharePoint list in Power Automate

Create a SharePoint list using Power Automate

So your flow is creating a new SharePoint site and now you want to create a SharePoint list in the site as well. Can this be done in Power automate?

SharePoint REST API and Power Automate

In the past I wrote many posts about how to do things in SharePoint with Power Automate. so far I haven’t had a need to create SharePoint list yet.

SharePoint REST API and Power Automate flows.

In the past I tried many of the options available with the Send and HTTP request to SharePoint . I collected all these posts in the User Guide to the REST API in Power Automate.

Today I’m going to add a list to a SharePoint site.

Create a SharePoint list to a SharePoint site

First I’m going to add a simple list to the site

Within the Site address i’m selecting my site collection in SharePoint.

Within the Method I’m using POST

and the Uri points at the _api/web/lists end point.

Create a SharePoint list using Power Automate 1

Nothing too complicated.

The body, I’m setting to the following json:

{
  "AllowContentTypes": true,
  "BaseTemplate": 100,
 "ContentTypesEnabled": true,
 "Description": "My list description",
 "Title": "Test"
}
Create a SharePoint list

And my list is created!

Now we need to add some columns

Adding a column to a SharePoint list

The next step is to create a custom column.

First I’m going to add a column, that of the simply text type.

Create a SharePoint list using Power Automate 2

The body

{ '__metadata': { 'type': 'SP.Field' }, 
     'FieldTypeKind': 2, 
     'Title':'My Custom Column'
}
   

If you need to create other types of columns then please have a look at the list of column types.

Now come the important questions…

  • Should we use site columns?
  • Should we use content types?
  • Should we add this column to the content type?

For a very long time i thought that SharePoint was all about content types and site columns. In the 2007 and 2010 versions of SharePoint, we ‘proper developers’ deployed everything using SharePoint solutions.

Every project we spend a lot of time getting the content types and site columns right.

But now that content types is harder and harder to configure. Should we still bother?

When you create a new team in Microsoft Teams and a document library holds my documents is created. Things like Site Settings are multiple clicks away and hidden away under site information.

This while adding new fields to SharePoint lists has been made so much easier.

Create a SharePoint list using Power Automate 3

Ok, there may still be some needs for content types, e.g. if you want to connect a selective group columns to types of data, but often multiple lists or libraries could do that as well.

The other important reason for site columns for me has always been to ensure that my columns are called the same within the lists where I use the columns. With the method described in this post I can get that done.

Is it possible to create content types and use site columns with the SharePoint REST API approach?

Create a content type

It is possible to do a POST to _api/web/contenttypes and then a body like this will create you a content type:

{
   'Name': 'New Content Type', 
   'Description': 'New Content Type Description',
   'Group': 'Custom Content Type Group'
}

Retrieve Site column details

Before we can add a site column to a list we will first need to retrieve it from the site. by calling the following end point.

/_api/web/Fields/getbytitle('My Site Column')/SchemaXml

The above end point is called with a GET method resulting in the SchemaXml of the field to be returned

Create a SharePoint list using Power Automate 4

Create a site column as a list column

By calling /_api/web/lists/getByTitle(‘List Name’)/fields/createfieldasxml with a POST method. You can use a site column

{
                   'parameters': {
                       '__metadata': { 'type': 'SP.XmlSchemaFieldCreationInformation' },
                       'SchemaXml': 'columnSchema
'
                   }
}

We are now ready to use the SchemXml that we retrieved for the field.

In the flow we will need to collect the SchemXml by collecting it from the earlier REST API call.

@{outputs('Send_an_HTTP_request_to_SharePoint_3')?['body/d/SchemaXml']}
Create a SharePoint list using Power Automate 5

And when we run that the flow will be successful in creating the site column on the list.

Create a SharePoint list using Power Automate 6

And on the SharePoint list I’ve got my column replicated.

Create a SharePoint list using Power Automate 7

2 thoughts on “Create a SharePoint list using Power Automate

    1. I believe that that doesn’t work. The answer is yes for the out of the box list templates but the answer is no fro the list templates that you created with save as list template. There is a problem with the list template ID if I remember that correctly. But then I never liked to use that option anyway.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: