Discourse API 'update category' required parameters

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