Expose Category and Group IDs to admins

AI-generated summary

In a discussion titled ‘Expose Category and Group IDs to admins,’ user outofthebox requested that Category and Group IDs be made visible to administrators to simplify editing Data Explorer queries. In response, supermathie provided several existing methods to retrieve these IDs, including SQL queries within the Data Explorer, accessing categories.json via the command line, and using the browser’s JavaScript console.

User simon suggested a parameterized SQL approach for the Data Explorer to avoid manual ID lookups entirely. jericson noted that while category IDs are easily found in the URL, group IDs remain difficult to locate, suggesting they should be displayed on the group profile management page. RGJ shared a general tip that appending .json to any URL often reveals the necessary IDs, a suggestion confirmed by Shirly_Nowak. Finally, JammyDodger advocated for adding dropdown parameters for IDs directly within the Data Explorer interface to further streamline the process.

Hi, I think it would make it easier for admins to edit data explorer queries if it was easier to find Category and Group IDs. If this information was made visible to accounts with admin status it wouldn’t bother most people while making it simple to find for those who need access.

Alternatively, in the meantime, if there are already easy ways to find Category and Group IDs, I’m eager to learn how to find this information.

1 Like

I’ll admit it’s not super easy to find if you don’t know where to look, but here’s a couple ways:

  • Data Explorer query:

    SELECT name, id FROM categories ORDER BY name
    
  • via categories.json

    curl https://meta.discourse.org/categories.json | jq '.category_list.categories[] | [.name,.id]'`
    …info for all categories…
    
    curl https://meta.discourse.org/categories.json | jq '.category_list.categories[] | select(.name == "feature").id'
    2
    
  • via the JS console in the browser, e.g.:

    > Discourse.Category.findBySlug('feature').id
    2
    
13 Likes

For Data Explorer queries, you can use a pattern similar to the WHERE statement in this query to avoid having to lookup category or group ids:

--[params]
-- string :category_name

SELECT
id AS topic_id
FROM topics t
WHERE t.category_id = (SELECT id FROM categories WHERE name = :category_name)
7 Likes

Bumping this topic because I had the same question. For categories, it’s relatively easy to look at the URL:

https://meta.discourse.org/c/announcements/67
                                           ^^

But I can’t find anything like that for groups. An ideal location for that would be on the group profile page (/g/[group_name]/manage/profile) somewhere. It’s not a huge problem of course (Data Explorer is my security blanket), but it is an annoyance when working with the API.

For anything internal-ish you can just tack .json after an URL. Also works for those pesky post ID’s.

6 Likes

My vote for the data explorer would be for more user_id style parameters like this Contribute > Feature request for groups:

5 Likes

Thanks for this tip :smiley:

2 Likes