category is not returned when searching for categories.json

I’m using the api and passing the username to return the categories.
But I noticed that when accessing the discourse this user also does not have category visibility in some places. As shown in the photo below, it appears in the side menu but does not appear in the category search.

And if I press ‘Graduation’ on my side, it works normally, because the user has the necessary permission.

[image]

Do you have that category lazy load setting turned on?

1 Like

No, I don’t.

I will explain the flow of our operation.

  1. We create the user by calling the API;
  2. We set the permissions that this user needs via API.
  3. After permissions are ok. the student searches for all categories via the categories.json route, adding the Api-Username in the request header according to the documentation.

At this point the search does not return the ‘Graduate’ category, the others return correctly, this category has the ‘everyone’ permission and also another specific one for the user as shown in the printout.

These are the user’s permissions.

I keep feeling @nbianca/@daniel that we should just have a special API endpoint for categories, that is

  1. Trivial … just lists all the categories ordered alphabetically in an index friendly way, alpha is probably easiest … sub categories don’t matter, they are listed as well

  2. Paginated, so you can ask for page 1 / 2/ 3 etc…

Current logic of trying to keep parent with children is too complex to order on this would solve the problem for “I just want a full category list for the site”

In the mean time @edu_moura I recommend just leaning on data explorer here, you can expose a single query to the API in a secure and scoped way.

1 Like

Very cool, I’ll try it.

But I still don’t understand why this search doesn’t return the ‘Graduação’ category for some students, and now I did another test and added a category return the graduation group as shown in print.


In the printout, group 1 is actually the necessary group, but there is no publication yet. Now group 2 was the one I added as a test for this user and then made the search return the category as necessary.

You can also get the categories from the categories property that’s returned from /site.json. Making a request to that route with the API Username of the user you are getting the categories for should return a full list of the categories (including subcategories) that they can see.

This would be great. Something similar to what’s returned from the site.json categories property without having to pull in all the other data that’s returned from site.json would be useful.

At the risk of making things overly complex, it might be useful to return some data about a category’s group restrictions. I don’t think there’s a straightforward way of knowing that now - other than actually making a request to the category on a user’s behalf.

This could be useful for the WP Discourse plugin. It pulls in categories using an admin username and saves them to the WordPress database. The categories are displayed to all WordPress authors on the post edit page, even if they don’t have permission to publish to a particular category. (Note that they can’t publish to categories they don’t have permissions for, but they can see categories on WordPress that they can’t see on Discourse.)

2 Likes