How to create a SharePoint List using Power Automate?

Summary

Many times the application I have built requires the list to be created on a Site. I found in GitHub sample app (by April Dunnam) to create this list(s) using REST call in Power Automate. I will document this approach for creating a ‘ Room Occupancy Tracking’ list and two fields.

Step by Step

Basically you will need the Send HTTP Call.

#1 To create a brand new list

Section of Send HTTPSection Value
Site Addresshttps://contoso.sharepoint.com/sites/OccupancyTracker
MethodPOST
Uri/_api/web/lists
Send HTTP call to create a brand new list
---- Headers ----

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



---- Body    ----
{
   "__metadata": {"type": "SP.List"},
   "AllowContentTypes": true,
   "BaseTemplate": 100,
   "Description": "Blah Blah.",
   "Title": "Room Occupancy Tracking"
}

#2 Create a Number type Column named Max Occupancy. Note: FieldTypeKind

Section of Send HTTPSection Value
Site Addresshttps://contoso.sharepoint.com/sites/OccupancyTracker
MethodPOST
Uri_api/lists/getbytitle(‘Room Occupancy Tracking’)/fields
Send HTTP call to create a Number type field
---- Headers ----

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

---- Body    ----


{
  '__metadata': {'type':'SP.Field', 'addToDefaultView': 'true' },
  'FieldTypeKind': 9,
  'Title': 'Max Occupancy'
}

#3 Create a Choice type field named Type.

Section of Send HTTPSection Value
Site Addresshttps://contoso.sharepoint.com/sites/OccupancyTracker
MethodPOST
Uri_api/lists/getbytitle(‘Room Occupancy Tracking’)/fields
Send HTTP call to create a Number Choice type field
---- Headers ----

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

---- Body    ----

{ 
     '__metadata':
     { 'type': 'SP.FieldChoice', 'addToDefaultView': 'true' },
     'Title': 'Question Type',
     'FieldTypeKind': 6,
     'Required': 'true',
     'Choices': { 'results': ['Single Line of Text', 'Yes No' ] }
}

#4 Add above fields to the default view. You will need an array of the field names, iterate over each name and make the following call.

Section of Send HTTPSection Value
Site Addresshttps://contoso.sharepoint.com/sites/OccupancyTracker
MethodPOST
Uri_api/web/Lists/getByTitle(‘Room Occupancy Tracking‘)/views/GetByTitle(‘All%20Items’)/ViewFields/AddViewField(‘Question Type’)/fields
Headers
Body
Send HTTP call to create a Number Choice type field

----- uri -----
_api/web/Lists/getByTitle('Room Occupancy Tracking')/views/GetByTitle('All%20Items')/ViewFields/AddViewField('Question Type')/fields

Conclusion

The above steps provided is a way to create a brand new list using a SharePoint REST call.

Keep the following SharePoint REST Wall Poster as a reference.

SharePoint 2013 REST Syntax (wall posters)

About Pankaj

I am a Developer and my linked profile is https://www.linkedin.com/in/pankajsurti/
This entry was posted in Power Automate. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s