I've been trying to create a modern calendar list in SharePoint using the REST API through Power Automate.
When using the UI, the only way I've seen how to do this is by first creating a modern list, adding Start and End Date fields, then creating the modern calendar view with those fields. (For my purposes all I need are Title, Start Date, and End Date.)
Following that same process through the REST API, I am able to create the list and fields just fine.
However, there doesn't seem to be any documentation on specifying the Start and End date fields for the modern calendar view, so when first opening the view, it gives this nasty popup telling the user to select the Title, Start, and End dates that the view will use:
Calendar View first opening popup
The body of my query is:
{ '__metadata': { 'type': 'SP.View'},
'ViewType': 'HTML',
'ViewType2':'MODERNCALENDAR',
'Title': 'Calendar',
'DefaultView': true
}
From what I've seen when I query for a calendar view that works, the only properties that seem to have anything to do with Start and End Dates are ListViewXml
and HtmlSchemaXml
, but neither of those explicitly state which fields are being used for the Start and End date in the view.
Correct ListViewXML
Example:
<View Name=\"{F0105F06-6621-44AD-9E25-F3D0928D3048}\" Type=\"HTML\" DisplayName=\"Calendar\" Url=\"/sites/Test-1/Lists/Calendar/Calendar.aspx\" Level=\"1\" BaseViewID=\"1\" ContentTypeID=\"0x\" ImageUrl=\"/_layouts/15/images/generic.png?rev=47\" ><Query /><ViewFields><FieldRef Name=\"Start_x0020_Date\" /><FieldRef Name=\"End_x0020_Date\" /><FieldRef Name=\"LinkTitle\" /></ViewFields><RowLimit Paged=\"FALSE\">30</RowLimit><JSLink>clienttemplates.js</JSLink><XslLink Default=\"TRUE\">main.xsl</XslLink><ViewType2>MODERNCALENDAR</ViewType2><ViewData><FieldRef Name=\"LinkTitle\" Type=\"CalendarMonthTitle\" /><FieldRef Name=\"LinkTitle\" Type=\"CalendarWeekTitle\" /><FieldRef Name=\"LinkTitle\" Type=\"CalendarWeekLocation\" /><FieldRef Name=\"LinkTitle\" Type=\"CalendarDayTitle\" /><FieldRef Name=\"LinkTitle\" Type=\"CalendarDayLocation\" /></ViewData><Toolbar Type=\"Standard\"/></View>
Correct HtmlSchemaXml
Example:
<View Name=\"{F0105F06-6621-44AD-9E25-F3D0928D3048}\" Type=\"HTML\" DisplayName=\"Calendar\" Url=\"/sites/Test-1/Lists/Calendar/Calendar.aspx\" Level=\"1\" BaseViewID=\"1\" ContentTypeID=\"0x\" ImageUrl=\"/_layouts/15/images/generic.png?rev=47\"><Query /><ViewFields><FieldRef Name=\"Start_x0020_Date\" /><FieldRef Name=\"End_x0020_Date\" /><FieldRef Name=\"LinkTitle\" /></ViewFields><RowLimit Paged=\"FALSE\">30</RowLimit><ViewType2>MODERNCALENDAR</ViewType2><Toolbar Type=\"Standard\" /><ViewData><FieldRef Name=\"LinkTitle\" Type=\"CalendarMonthTitle\" /><FieldRef Name=\"LinkTitle\" Type=\"CalendarWeekTitle\" /><FieldRef Name=\"LinkTitle\" Type=\"CalendarWeekLocation\" /><FieldRef Name=\"LinkTitle\" Type=\"CalendarDayTitle\" /><FieldRef Name=\"LinkTitle\" Type=\"CalendarDayLocation\" /></ViewData><XslLink Default=\"TRUE\">main.xsl</XslLink><JSLink>clienttemplates.js</JSLink><ParameterBindings><ParameterBinding Name=\"NoAnnouncements\" Location=\"Resource(wss,noXinviewofY_LIST)\" /><ParameterBinding Name=\"NoAnnouncementsHowTo\" Location=\"Resource(wss,noXinviewofY_DEFAULT)\" /></ParameterBindings></View>
My question is, is there a better way to do what I'm trying to do OR is there a way to specify the Start and End dates that the calendar view will use through the REST API call?