0

I am looking to update my list default view (All Items) using REST API, what i am looking exactly is to show/hide columns.

When i checked the result of this request:

https://m365x873105.sharepoint.com/sites/<Site Name>/_api/web/lists/getByTitle('<List Name>')/views

It appears that there is a certain fields that should be edited in order to update the View, the field are colored in the picture below:

enter image description here

Now i should implement a POST request with the proper Headers in order to update the view, that's my try which is not working:

enter image description here enter image description here enter image description here

What am I missing here ! please.

2 Answers 2

1

I just found the answer to my question

there is some endpoints which are useful to edit, i get to manage my issue by removing all the fields with one request, then add every single field i want it to appear in the default view one by one. please go refer to the following links:

Remove All fields

Add field

Move field to

Fortunately i found these endpoints.

0

get your view : /_api/web/lists/getByTitle('Pages')/Views/getByTitle('test')

and set it to default view

function UpdateList(){ var listName="Pages"; var list = { "__metadata": { "type": 'SP.View' }, "DefaultView": true };

jq.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Pages')/Views/getByTitle('test')",
    type: "POST",
    contentType: "application/json;odata=verbose",
    data: JSON.stringify(list),
    headers: {
        "Accept": "application/json;odata=verbose",
        "X-RequestDigest": jq("#__REQUESTDIGEST").val(),
        "X-HTTP-Method": "MERGE",
        "If-Match": "*"
    },
    success: function (data) {
        alert('Success');
        window.location.href=window.location.href;
    },
    error: function (data) {
        console.dir(data);
    }
});

} UpdateList();

3
  • Hello Frederic, this will only set the selected view as default, doesn't it ? Commented Nov 21, 2019 at 14:25
  • Hello Aimen, yes, it's ok on my SP2016 Commented Nov 21, 2019 at 14:47
  • That's not what i am looking for, i said i want to update this default view by showing and hiding columns Commented Nov 22, 2019 at 6:37

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.