No Code Attached Yet Information Required
avatar lushdomain
lushdomain
12 Oct 2024

Steps to reproduce the issue

I am working on an app that uses the Joomla API to query articles in a specific category.

Example: api/index.php/v1/content/articles?filter[category]=2

However, this returns all articles regardless of their published state. Which in turn is causing other issues in the way I'm processing the returned json data.

That aside:

I used the filters option in the URL to only return those articles that are either published [1], or unpublished [0]

api/index.php/v1/content/articles?filter[category]=2&filter[state]=1&filter[state]=0

However, this does not work.

Regardless of the order I place the filters, only the last filter in the string is being returned.

Example 1: api/index.php/v1/content/articles?filter[category]=2&filter[state]=1&filter[state]=0

Returns only a list of unpublished articles

Example 2: api/index.php/v1/content/articles?filter[category]=2&filter[state]=0&filter[state]=1

Returns only a list of published articles

I also tried concatenated versions, which returned the json results, but again only the final part.

api/index.php/v1/content/articles?filter[category]=2&filter[state]=1,0

api/index.php/v1/content/articles?filter[category]=2&filter[state]=[0,1]

ETC...

It would seem from the online Postman documentation that Joomla can accept multiple filters in the same URL

For example when querying users:

Example: /api/index.php/v1/users?filter[groupid]=8&filter[state]=0&filter[registrationDateEnd]=2099-12-31T20%3A36%3A01Z' \

But, in this case for article retrieval maybe not, or there is a bug.

Expected result

The API to return all published and unpublished articles in the selected category

Actual result

Only articles linked to the last filter in the API url are being returned.

System information (as much as possible)

Joomla 5.1.4 php 8.2

Additional comments

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar lushdomain lushdomain - open - 12 Oct 2024
avatar lushdomain lushdomain - change - 12 Oct 2024
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 12 Oct 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 12 Oct 2024
avatar brianteeman
brianteeman - comment - 12 Oct 2024

When using filters I believe that the filters are published and category_id

not at my pc to check

avatar richard67
richard67 - comment - 13 Oct 2024

@lushdomain Try the following:
api/index.php/v1/content/articles?filter[category]=2&filter[state][]=0&filter[state][]=1.
Mind the new array element [] after the filter[state].
Does that work?

avatar lushdomain
lushdomain - comment - 13 Oct 2024

@richard67 It works, but not as I'd expect. I did look at this option before, but couldn't get it to work either at the time. However, with pared down articles for testing, ie 2 (1 published and 1 unpublished) it does work to return both articles.

However, there is a new twist now.

/api/index.php/v1/content/articles?filter[category]=2&filter[state][]=0 returns unpublished as well as published.
/api/index.php/v1/content/articles?filter[category]=2&filter[state][]=1 returns published as well as unpublished.

/api/index.php/v1/content/articles?filter[category]=2&filter[state][]=0&filter[state][]=1 returns unpublished and published.

The json response seems to place the unpublished article first regardless of how the url is structured, I don't know if this matters or is a normal response.

avatar richard67
richard67 - comment - 13 Oct 2024

However, there is a new twist now.

/api/index.php/v1/content/articles?filter[category]=2&filter[state][]=0 returns unpublished as well as published.
/api/index.php/v1/content/articles?filter[category]=2&filter[state][]=1 returns published as well as unpublished.

/api/index.php/v1/content/articles?filter[category]=2&filter[state][]=0&filter[state][]=1 returns unpublished and published.

@lushdomain You have to use the [] only when specifying more than one value so the filter[state] shall be an array. When only filtering for one value, do not use []. If the following works for you then it works as desired:

/api/index.php/v1/content/articles?filter[category]=2&filter[state]=0

returns unpublished only.

/api/index.php/v1/content/articles?filter[category]=2&filter[state]=1

returns published only.

/api/index.php/v1/content/articles?filter[category]=2&filter[state][]=0&filter[state][]=1

returns unpublished and published but not archived and not trashed.

avatar richard67
richard67 - comment - 13 Oct 2024

In general use somearray[somekey]=value to assign one value to that somearray[somekey], so the somearray[somekey] is a scalar, and use somearray[somekey][]=value1&somearray[somekey][]=value2&somearray[somekey][]=value3 to assign mutliple values so the somearray[somekey] is an array.

avatar Quy
Quy - comment - 13 Oct 2024

Example: api/index.php/v1/content/articles?filter[category]=2

However, this returns all articles regardless of their published state. Which in turn is causing other issues in the way I'm processing the returned json data.

Are you sure? For me, it returns published and unpublished articles only without having to specify state filter.

avatar Quy Quy - change - 14 Oct 2024
Labels Added: Information Required
avatar Quy Quy - labeled - 14 Oct 2024
avatar alikon
alikon - comment - 17 Oct 2024

i can confirm there is no need of filter cause the endpoint returns both published and unpublished

avatar Quy Quy - change - 17 Oct 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-10-17 11:49:40
Closed_By Quy
avatar Quy Quy - close - 17 Oct 2024
avatar Quy
Quy - comment - 17 Oct 2024

Closing as non-reproducible.

Add a Comment

Login with GitHub to post a comment