0

I have a list view in which I need to change the column order every quarter of the year. Is there a method using rest API to set all my visible columns to a specific order, and then add a new one and drop an old one each quarter?

1 Answer 1

1

Yes, you can edit your view to add, move or remove fields with SharePoint REST API. It's working for both on-premise, including SharePoint Server 2013 and later, and SharePoint Online in Microsoft 365.

Sample of requests:

Get current view fields (GET)

GET https://your-webapp/sites/your-site/_api/web/lists/getByTitle('YourList')/views/getByTitle('All%20Items')/viewFields

Add a field from a view (POST)

POST https://your-webapp/sites/your-site/_api/web/lists/getByTitle('YourList')/views/getByTitle('All%20Items')/viewFields/addViewField
'Content-Type': 'application/json;odata=verbose'
'Accept': 'application/json;odata=verbose'

{ "strField": "Status" }

Remove a field from a view (POST)

POST https://your-webapp/sites/your-site/_api/web/lists/getByTitle('YourList')/views/getByTitle('All%20Items')/viewFields/removeViewField
'Content-Type': 'application/json;odata=verbose'
'Accept': 'application/json;odata=verbose'

{ "strField": "Status" }

Remove all fields from a view (POST)

POST https://your-webapp/sites/your-site/_api/web/lists/getByTitle('YourList')/views/getByTitle('All%20Items')/viewFields/removeAllViewFields
'Content-Type': 'application/json;odata=verbose'
'Accept': 'application/json;odata=verbose'

Change field order from a view (POST)

 POST https://your-webapp/sites/your-site/_api/web/lists/getByTitle('YourList')/views/getByTitle('All%20Items')/viewFields/moveViewFieldTo
'Content-Type': 'application/json;odata=verbose'
'Accept': 'application/json;odata=verbose'

{ "field": "Status", "index": 2 }

Screenshots (with SharePoint Online & Power Automate): requests responses results

Sources:

3
  • 1
    Wow!!! Fantastic! Thank you
    – ChasEpes
    Dec 6, 2023 at 16:30
  • Sorry. Correction. Can you tell me what the headers are for this Post?
    – ChasEpes
    Dec 6, 2023 at 19:02
  • 1
    Oh sorry, I updated my answer with headers and screenshots.
    – jleture
    Dec 7, 2023 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.