Discourse API 'update category' required parameters

AI-generated summary

The discussion revolves around the Discourse API’s update category route, where users andrew5 and jericson express frustration that name, color, and text_color are required parameters even when only one attribute, like parent_category_id, is being updated. They note that this forces additional API calls to retrieve current values. blake acknowledges the issue and confirms that the requirement has been removed in a recent update, allowing users to update a category without specifying name, color, or text_color unless those fields are being changed. blake provides a commit link showing the fix, though the name field remains required for category creation.

Why are the name, color, and text_color attributes required for the update category route
(Discourse API Docs)?

It seems like attributes such as the slug should be able to be updated without specifying any other attributes.

I find this slightly irritating too. When updating other information about a category I don’t necessarily know the category’s color and text_color. So my options are to change both to something innocuous or add another API call to collect that information first. Here’s an example using the discourse_api gem:

response = client.categories

cat = response.find {|e| e['name'] == 'Category Name'}

response = client.update_category(
  id: cat['id'],
  name: cat['name'],
  color: cat['color'],
  text_color: cat['text_color'],

  # Add attribute(s) you actually want to update below
  parent_category_id: 7, # I'm nesting a bunch of categories under #7
)

Obviously I won’t always know the category name either. I definitely need to look that up before updating the category.

It would be handy if those parameters weren’t required. Alternatively, could there be some sort of syntax to signal “I don’t want to change the field”? Like if you pass _ it just sets that attribute to the current value. (I’m not sure what the reason is for the required fields, so I’m tossing out ideas that may or may not be useful.)

I agree. I don’t think color fields should be required on update. They probably shouldn’t be required on create either. I’ll look into this and see what I can improve here.

I just pushed an update for this :slight_smile:

https://github.com/discourse/discourse/commit/c68563a281b64e00affd8b56e1d06528697a6e4e

When creating a category the name field is still required, but when updating the category you no longer have to specify the name, color, and text_color in addition to the actual property you want to update.