9

The below will get a list containing all fields

$.ajax({
    url: "http://<site url>/_api/web/lists/GetByTitle('ListTitle')/items?$select=*"
    ,type: "GET",
    dataType: "json",
    headers: {
    Accept: "application/json;odata=verbose"
    }
});

Say I want to retrieve all fields excluding the Title field... Is there a way to express this without writing out all fields (minus the Title field)? i.e. is there a way to exclude a field explicitly?

I am thinking something like this

url: "http://<site url>/_api/web/lists/GetByTitle('ListTitle')/items?$select!=Title

which surprisingly does not throw an error and returns all fields including Title...

or

url: "http://<site url>/_api/web/lists/GetByTitle('ListTitle')/items?$select=*&exclude=Title

exclude is not a valid query option, so obviously this fails.

Is there anything clever I can do to exclude a field or is this not possible?

7
  • 2
    Is there an issue with retrieving all fields and just not using the title field in the returned results? I understand you are querying more information so performance could take a slight hit, but I wouldn't imagine it being substantial.
    – Jordan
    Dec 16, 2015 at 17:53
  • I hope that there is no such techniques .I do get all fields like /_api/SP.AppContextSite(@target)/web/lists/getbytitle('Custom List')/Fields
    – user13408
    Dec 16, 2015 at 17:53
  • and if you want to get all but not title then your way like this is option only $select=Price,effectivebasepermissions,bla,bla
    – user13408
    Dec 16, 2015 at 17:59
  • Jordan - the issue is I am loading the json into a DataCollection object (DataCollection.js library)... then making a 2nd sharepoint rest call on another list, and joining the results from the 2nd call onto the DataCollection.... So duplicate fields are an issue for me. I'm happy to explain more of the process if what I'm typing is not understood
    – Devin
    Dec 16, 2015 at 18:00
  • Programmer - I understand that you can select fields explcitly, I am wondering about excluding fields explicitly. The reason being, if a field is added to the list, I want the REST call to retrieve the new field without updating the code.
    – Devin
    Dec 16, 2015 at 18:01

2 Answers 2

14

Like I mentioned in my comment, a simple workaround would be to traverse through the json results and delete the Title for each

var call = $.ajax({
   url: "http://<site url>/_api/web/lists/GetByTitle('ListTitle')/items?$select=*"
   ,type: "GET",
   dataType: "json",
   headers: {
   Accept: "application/json;odata=verbose"
 }
});

 call.done(function (data,textStatus, jqXHR){
     var dataArray = data.d.results;
     for (var i in dataArray) {
      delete data.d.results[i].Title;
     }
 });
1
  • 2
    functionally this works for me.. if i could upvote you I would!
    – Devin
    Dec 16, 2015 at 18:52
8

Below is the list of supported operators for SharePoint REST APIs. There is no way to specify all but one.

enter image description here

REF: https://msdn.microsoft.com/en-us/library/office/fp142385.aspx#sectionSection0

4
  • Thank you Ashish, I selected Mike for the answer since he came up with a clever work around, but this also answers my question.
    – Devin
    Dec 16, 2015 at 18:57
  • Not a problem but I think two server trips is not worth getting an extra field from server, no? Dec 16, 2015 at 19:18
  • only one trip is being made, what extra field are you referring to? I am removing a field
    – Devin
    Dec 16, 2015 at 19:42
  • sorry, I thought you were getting fields first and then forming a $select with all available fields except title. I didn't realize that you wanted to remove title from results. Dec 16, 2015 at 19:54

Your Answer

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

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