# Discourse API 'update category' required parameters

**URL:** https://meta.discourse.org/t/discourse-api-update-category-required-parameters/132424
**Category:** Development
**Tags:** rest-api
**Created:** [November 2, 2019, 12:47am UTC](https://meta.discourse.org/t/discourse-api-update-category-required-parameters/132424 "2019-11-02T00:47:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![andrew5](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@andrew5](https://meta.discourse.org/u/andrew5)
#### Post date: [November 2, 2019, 12:47am UTC](https://meta.discourse.org/t/discourse-api-update-category-required-parameters/132424/1 "2019-11-02T00:47:20Z")

</div>

Why are the `name`, `color`, and `text_color` attributes required for the update category route  
([Discourse API Docs](https://docs.discourse.org/#tag/Categories/paths/~1categories~1%7Bid%7D/put))?

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

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [August 7, 2020, 3:56pm UTC](https://meta.discourse.org/t/discourse-api-update-category-required-parameters/132424/2 "2020-08-07T15:56:14Z")

</div>

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](https://github.com/discourse/discourse_api):

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

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [August 7, 2020, 5:58pm UTC](https://meta.discourse.org/t/discourse-api-update-category-required-parameters/132424/4 "2020-08-07T17:58:08Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [August 12, 2020, 6:43pm UTC](https://meta.discourse.org/t/discourse-api-update-category-required-parameters/132424/5 "2020-08-12T18:43:24Z")

</div>

I just pushed an update for this 🙂

[https://github.com/discourse/discourse/commit/c68563a281b64e00affd8b56e1d06528697a6e4e](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.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [September 11, 2020, 6:47pm UTC](https://meta.discourse.org/t/discourse-api-update-category-required-parameters/132424/6 "2020-09-11T18:47:29Z")

</div>

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