I am currently stuck on a problem that I have found no solution for. We use our own API to make calls to Sitefinity and return objects called Insights
. We are currently trying to only return insights that have the IsFeatured
value set to yes
. This is returned as either a 1
or a 0
.
The problem from what I can see is lying in my query string. I came to this conclusion because at first we were using the query $"/insights?$orderby=PublishDate&$top={topN}"
. This returned the insights as expected, ordered by PublishDate and only bringing back the value we input, for example 3
.
The problem occurred when I tried to add the filter to the query. It currently looks like this: $"/insights?$filter=contains(IsFeatured, 1)&$orderby=PublishDate&$top={topN}"
. However when it runs it returns the code 400 for bad request.
According to the Sitefinity documentation this is how to use filter:
We have also used the filter before like in this example:
$"/insights?$filter=contains(InsightCategory, 'NEWSLETTER')&$orderby=PublishDate&$skip={skip}&$top={take}"
and this works as expected.
I have tried a few variations to try get it to work but all the requests return 400. Some more info that might help is that the type returned for IsFeatured is an int. Also the value is being returned on this call: $"/insights?$orderby=PublishDate&$top={topN}"
. I can see this in the results:
Also the syntax with uppercase is right because as seen above with the filter request that worked it uses the same syntax. I have also tried replacing the 1
with a 0
to test but this also failed.
The Choice fields are a bit different from the rest. See this article on how to filter by a choice field.
Filter a collection by ChoiceField value
NOTE: When working with ChoiceField through the OData web services, the field value is returned as a number (e.g. 2, 4, 8) instead of the actual selected textual value in this field (e.g. Option1, Option2, Option3). The returned value indicates which choice option has been selected. It is returned as the 2 to the power of the position of that choice in the collection of all choices (2n). For example, if you have configured your ChoiceField with 4 options - Option 1, Option 2, Option 3, Option 4 the value which will be returned by the service will be:
If the selected option is Option 1, the service returns 1 (2 to the power of 0) If the selected option is Option 2, the service returns 2 (2 to the power of 1) If the selected option is Option 3, the service returns 4 (2 to the power of 2) If the selected option is Option 4, the service returns 8 (2 to the power of 3)