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