I am trying to create a SharePoint list view through the SharePoint REST API, with a defined set of columns to be part of the view. The endpoint i am using is below:
POSTMAN API Request:
HTTP METHOD: POST
URL: https://tenantname.sharepoint.com/sites/SPSite/_api/web/lists/getbytitle('ListName')/views Headers:
- 'Accept' - 'application/json;odata=verbose'
- 'Content-Type' - 'application/json;odata=verbose'
Body (JSON):
{
"__metadata":{
"type":"SP.View"
},
"Title":"TestView",
"ViewFields":["Title","Name"]
}
I get a JSON error, since this payload does not seem to be right. Need help in understanding how to create a view with specific fields through the SharePoint REST API.
Thanks, Yesh
When creating view, it's not supported to add viewFields, this needs to be done after creating list view.
So please create the view like this firstly:
Then set Viewfield for the new created List View like this:
So the above sample is adding "Created" field into viewFields and View Guid is alert in first rerquest, use it in second request.