Discourse API 'update category' required parameters

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.

3 Likes

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.)

1 Like

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.

2 Likes

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.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.