Filtering and sorting operations

Filtering a collection

Request type: GET

Format: {{baseurl}}/api/default/{{entity}}?$filter=

The $filter system query option can be used to filter any collection of resources.

NOTE: The response to a filtered collection is a collection of the same type, regardless of the number of matched resources

Filter by field value

Request type: GET

Format: {{baseurl}}/api/default/{{entity}}?$filter=contains({{fieldname}},{{value}})

To filter by field value, you need to specify the field name and the field value. For example, if you want to get the news items, whose Title field contains the word “Boston”, you must use: https://mysite.com/api/default/news?$filter=contains(Title, ‘Boston’)

Filter by language translation

Request type: GET

Format: {{baseurl}}/api/default/{{entity}}?sf_culture={{culture}}

You can query the items from a specific language culture when your Sitefinity is in multilingual mode. To do that you must use the sf_culture filter and append the desired culture. For example, if you want to get the news items that are translated in Spanish you must call: https://mysite.com/api/default/news?sf_culture=es. In this example, the English translations of the specified entity items are returned

Filter a collection by classification

Request type: GET

Format:

  • Filter by single taxon

    Format: {{baseurl}}/api/default/{{entity}}?$filter={{taxonomy_name}}/any(x:x eq {{taxon_id}})

  • Filter by multiple taxa from the same classification

    Format: {{baseurl}}/api/default/{{entity}}$filter={{taxonomy_name}}/any(s:s eq {{taxon_1_id}} or s eq {{taxon_2_id}}))

  • Filter by multiple taxa from different classifications

 Format: {{baseurl}}/api/default/{{entity}}?$filter=({{taxonomy_1_name}}//any(x:x eq {{taxon_1_id}}) and {{taxonomy_2_name}}//any(x:x eq {{taxon_2_id}}))

To filter a collection of items by the taxa they have been classified with, you must use the $filteroperator and specify the classification field name (for example, Tags, Categories, and so on) and the Id of the taxon you want to filter by. For example, to get a list of news items, that have been marked with the Tag “Weather” you must call: http://mysite.com/api/default/newsitems$filter=Tags/any(x:x eq E984FE07-0301-45E6-B3AE-078108DB7B01), where E984FE07-0301-45E6-B3AE-078108DB7B01 is the Id of the Weather tag. To narrow down filtering and get only the news items marked with the “Weather” tag and classified with the “North America” category you must say: http://mysite.com/api/default/newsitems$filter=(Tags/any(x:x eq E984FE07-0301-45E6-B3AE-078108DB7B01) and Category/any(x:x eq 22932D66-33C6-4B81-B351-5FF61D7043E7))

The /any operator enables you to use lambda expressions, so you can filter by multiple taxa from one or more classifications and specify the logical conditions.

Filter by provider

Request type: GET

Format: {{baseurl}}/api/default/{{entity}}?sf_provider={{providername}}

To filter any type of content by the content provider, you must use the sf_provider filter and append the provider name. This way only content from this provider will be returned. For example:  https://mysite.com/api/default/news?sf_provider=OpenAccessDataProvider. If you do not pass a provider filter, the service always returns content from the default provider.

Combine several filters

You can combine multiple filters to narrow down your request conditions. For example, you can get the news items in Spanish from a specific provider: http://mysite.com/api/default/newsitems?sf_culture=es&sf_provider=OpenAccessDataProvider

Filter a collection using logic operators

Request type: GET

Format: {{baseurl}}/api/default/{{entity}}?$filter=contains(Title, ‘Sample news item’) and PublicationDate gt 2018-01-01T00:00:00Z

You can use andor and not logical operators to create more complex filter clauses

Sort a collection

Request type: GET

Format: {{baseurl}}/api/default/{{entity}}?$orderby={{fieldname}} {{sortorder}}

You can use the $orderby system query option to request resources in ascending or descending order. To do this you must specify the field name you want to sort by and use the asc or desc keywords. For example, if you want to sort a list of news items  alphabetically by their Title you must use: http://mysite.com/api/default/newsitems?orderby=Title desc .

In case the sort order (asc or desc) is not specified, then the resources will be ordered in ascending order.

It is possible to sort by multiple fields, using comma separated format, for example http://mysite.com/api/default/newsitems?orderby=PublicationDate asc, Title desc

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

Common operations