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 HTTP | Section Value |
---|---|
Site Address | https://contoso.sharepoint.com/sites/OccupancyTracker |
Method | POST |
Uri | /_api/web/lists |
---- 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 HTTP | Section Value |
---|---|
Site Address | https://contoso.sharepoint.com/sites/OccupancyTracker |
Method | POST |
Uri | _api/lists/getbytitle(‘Room Occupancy Tracking’)/fields |
---- 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 HTTP | Section Value |
---|---|
Site Address | https://contoso.sharepoint.com/sites/OccupancyTracker |
Method | POST |
Uri | _api/lists/getbytitle(‘Room Occupancy Tracking’)/fields |
---- 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 HTTP | Section Value |
---|---|
Site Address | https://contoso.sharepoint.com/sites/OccupancyTracker |
Method | POST |
Uri | _api/web/Lists/getByTitle(‘Room Occupancy Tracking‘)/views/GetByTitle(‘All%20Items’)/ViewFields/AddViewField(‘Question Type’)/fields |
Headers | |
Body |
----- 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.