OData substring or start with returning all elements

I am trying to filter my results from a Rest call.

$.ajax({ type: "GET", headers: { "Accept": "application/json;odata=verbose" }, dataType: "JSON", url: _spPageContextInfo.webServerRelativeUrl + "/_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$startswith('Title','" + request.term + "') eq true", success: function (data) { }, error: function (ex) { } }); 

In my contact list, I'm trying to get a title and identifier for items that start with a string or that have a string somewhere in it, for example, this is the name of someone.

I also tried it with a substring:

 "/_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$substringof(" + request.term + ",'Title') eq true" 

which provides the same result.

It gives me all the elements of a list from a list and does not apply filtering. I create Url to relax after watching here Programming with the SharePoint 2013 REST service Like the diagram presented there, I think that Url looks fine, but it doesn't seem so :)

Edit:

Applying $filter , as in OData Uri Conventions, gives me the following error:

 {"error":{"code":"-1, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The query is not valid."}}} 

Tried it with the following query lines:

 _api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof(m,'Title') eq true _api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m','Title') eq true _api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m',Title) eq true 
+6
source share
5 answers

I managed to get a filter with a substring returning the correct results when I deleted "eq true".

Using one of the query strings, it should work as follows:

 _api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m',Title) 

I have not tested any other functions, but at least the same thing happens with the startswith function.

+10
source

For those who are looking at this question, I can report that

 /_api/web/lists/GetByTitle('Applications')/items?$filter=startswith(Title,'1AAJ') 

I work for me.

+6
source

Check http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/ for the correct uri agreement.

It should be "/ _api / lists / getByTitle ('Contacts') / items? $ Select = Name, Id & $ filter = substringof (" + request.term + ", 'Title') eq true"

So, with the $ filter enabled

0
source

I tried my request URI on my endpoint and applied some changes: - The second substring parameter should not be a string, so I removed the apostrophes

After that I get the results:

http://jaydata.org/examples/Northwind.svc/Products ? $ select = Product_ID, Product_Name & $ filter = substringof ('CH', Product_Name)

My endpoint is a standard WCF data service, and the filter works.

If changing the URI still returns all records, this will be a SherePoint trick, I think. What happens if you put "zzz" or some random string in a filter?

0
source

In addition, the contains method works, and I worked better with it. Syntax:

 api/People?$filter=contains(LastName,%27Smith%27)&$select=LastName,FirstName 
-1
source

All Articles