Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API filter checking boolean true against string "true" #1736

Closed
aamood opened this issue Apr 24, 2020 · 2 comments · Fixed by #2640
Closed

API filter checking boolean true against string "true" #1736

aamood opened this issue Apr 24, 2020 · 2 comments · Fixed by #2640
Labels

Comments

@aamood
Copy link

aamood commented Apr 24, 2020

I am trying to filter out unpublished entries with the API. I've tried both:
/api/collections/{collection}/entries?filter[published:isnt]=false
/api/collections/blog/entries?filter[published]=true

Both are returning empty.

@jasonvarga said in the discord server that the API is testing the boolean true against a string true and failing.

@jackmcdade jackmcdade added the api label Apr 27, 2020
@igregson
Copy link

igregson commented May 7, 2020

I've run into the same thing. The intuitive property to check here (as you point out, @aamood) is published, since that's returned as a top-level property for each collection entry. This property does not seem to work though. Checking the status works, though it doesn't seem to be a top-level entry property at all. The way to use it that is working for me is:

?filter[status:is]=published

And to negate it:

?filter[status:isnt]=published

or

?filter[status:not]=published

It's also worth nothing that unpublished entries are returned by default. It's unclear whether this is intended or not. If not, there should be an issue created for it (I'm happy to create it if need be).

@duncanmcclean
Copy link
Member

duncanmcclean commented Oct 12, 2020

I've submitted a pull request (#2640) which will cast true and false values in filters to booleans which will enable the filter addressed in the issue description to work correctly (ie. http://statamic.test/api/collections/pages/entries?filter[published]=true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants