# API for changing category groups

**URL:** https://meta.discourse.org/t/api-for-changing-category-groups/99857
**Category:** Development
**Created:** [October 18, 2018, 11:59am UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857 "2018-10-18T11:59:46Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Edwin\_Silva](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Edwin\_Silva](https://meta.discourse.org/u/Edwin_Silva)
#### Post date: [October 18, 2018, 11:59am UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/1 "2018-10-18T11:59:46Z")

</div>

I´m trying to add a group to a category via the api using postman.  
Is there a way to do that ?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [October 18, 2018, 12:01pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/2 "2018-10-18T12:01:27Z")

</div>

Yes, everything in Discourse has an API. You can learn the API endpoints for stuff you see in the UI using [Reverse engineer the Discourse API](https://meta.discourse.org/t/how-to-reverse-engineer-the-discourse-api/20576)

---

<div class="post-metadata">

### Author: ![Edwin\_Silva](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Edwin\_Silva](https://meta.discourse.org/u/Edwin_Silva)
#### Post date: [October 18, 2018, 2:28pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/3 "2018-10-18T14:28:50Z")

</div>

Isn’t there a other way to do it ?

---

<div class="post-metadata">

### Author: ![Edwin\_Silva](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Edwin\_Silva](https://meta.discourse.org/u/Edwin_Silva)
#### Post date: [October 18, 2018, 2:56pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/4 "2018-10-18T14:56:33Z")

</div>

I’m trying to assign a group to a category, so only people in that group can see this category.  
I know that there are some similar questions out there, where you can reverse engineer DIscourse.  
I want to change the marked property on the picture

 ![27](https://global.discourse-cdn.com/meta/original/3X/b/d/bdec0f096c10b4d6cca008797dfa1b02ecc95ce6.png) .  
In the second picture you can see what i tried inside postman  
 ![50](https://global.discourse-cdn.com/meta/original/3X/e/d/ed223a3233ec49603ced85aeaa648eaafbc4453f.png)

The number used in the request i got from trying to reverse engineer it as seen in the last picture

 ![23](https://global.discourse-cdn.com/meta/original/3X/b/8/b8598d6c96143ce5a6fb1116447ad776f2cfac02.png)  
Did I make some mistake in my put request?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [October 18, 2018, 3:07pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/5 "2018-10-18T15:07:03Z")

</div>

The `_` parameter isn’t actually required - it is just there as a “cache buster”. You can remove it.

Also, you are looking at the incorrect request in your developer tools. You should be looking at the request that happens when you click the “save” button. (You will need to tick “preserve log” in dev tools so that the request doesn’t dissappear when the page reloads). Look for a PUT request to `/categories/192`.

Another thing to watch out for is that your parameters need to be urlencoded. In postman, you do this by changing from “form-data” to “x-www-form-urlencoded”.

Hope that helps get you a little bit closer!

---

<div class="post-metadata">

### Author: ![Edwin\_Silva](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Edwin\_Silva](https://meta.discourse.org/u/Edwin_Silva)
#### Post date: [October 18, 2018, 3:20pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/6 "2018-10-18T15:20:19Z")

</div>

Thanks for the reply.  
I can´t seem to find the right request

---

<div class="post-metadata">

### Author: ![Edwin\_Silva](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Edwin\_Silva](https://meta.discourse.org/u/Edwin_Silva)
#### Post date: [October 18, 2018, 3:47pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/7 "2018-10-18T15:47:48Z")

</div>

Okay. I Think i found the right request.

 ![24](https://global.discourse-cdn.com/meta/original/3X/a/9/a9fe6e2160cd19efc829115e319a9e97061f2de0.png)

As seen in the picture below, then i want to change the permissions array.

 ![03](https://global.discourse-cdn.com/meta/original/3X/8/c/8c0bdbda60c180a961f1a0e698b9d03446d36b1b.jpeg)

I tried doing that inside postman, my put request returns bad request

 ![33](https://global.discourse-cdn.com/meta/original/3X/a/d/adacd9d3f21d321dbb0df3adad3caea67baf5fbc.png)

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [October 18, 2018, 3:53pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/8 "2018-10-18T15:53:24Z")

</div>

> [@david](#):
>
> Another thing to watch out for is that your parameters need to be urlencoded. In postman, you do this by changing from “form-data” to “x-www-form-urlencoded”.

You should not be using the “raw” option on postman

---

<div class="post-metadata">

### Author: ![Edwin\_Silva](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Edwin\_Silva](https://meta.discourse.org/u/Edwin_Silva)
#### Post date: [October 18, 2018, 3:55pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/9 "2018-10-18T15:55:11Z")

</div>

I tried that too

 ![35](https://global.discourse-cdn.com/meta/original/3X/b/f/bf2af940737e694ae26174d890ac24d88d634909.jpeg)

---

<div class="post-metadata">

### Author: ![mikechristopher](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mikechristopher/32/89135_2.png) [@mikechristopher](https://meta.discourse.org/u/mikechristopher)
#### Post date: [October 18, 2018, 4:51pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/10 "2018-10-18T16:51:41Z")

</div>

This is what I use when creating a category - I tend to use the form data however

 ![image](https://global.discourse-cdn.com/meta/original/3X/a/9/a9911919af47155204618f9b4b9af6861c65d942.png)

Another thing to check is your error logs - this helps you along the path to be able to identify any calls are incorrect

---

<div class="post-metadata">

### Author: ![Edwin\_Silva](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Edwin\_Silva](https://meta.discourse.org/u/Edwin_Silva)
#### Post date: [October 18, 2018, 5:13pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/11 "2018-10-18T17:13:31Z")

</div>

Does it work?  
And do you call your group name “1” ?

---

<div class="post-metadata">

### Author: ![mikechristopher](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mikechristopher/32/89135_2.png) [@mikechristopher](https://meta.discourse.org/u/mikechristopher)
#### Post date: [October 18, 2018, 5:30pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/12 "2018-10-18T17:30:41Z")

</div>

no the name of the group goes in the `[groupname]` section

It does work - I use that exact set up all the time.

---

<div class="post-metadata">

### Author: ![Edwin\_Silva](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Edwin\_Silva](https://meta.discourse.org/u/Edwin_Silva)
#### Post date: [October 18, 2018, 5:53pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/13 "2018-10-18T17:53:56Z")

</div>

So I could write permissons[random grop name]?

---

<div class="post-metadata">

### Author: ![mikechristopher](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mikechristopher/32/89135_2.png) [@mikechristopher](https://meta.discourse.org/u/mikechristopher)
#### Post date: [October 18, 2018, 6:06pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/14 "2018-10-18T18:06:18Z")

</div>

works for me - as long as the group exists of course first.

---

<div class="post-metadata">

### Author: ![Edwin\_Silva](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Edwin\_Silva](https://meta.discourse.org/u/Edwin_Silva)
#### Post date: [October 18, 2018, 7:17pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/15 "2018-10-18T19:17:49Z")

</div>

I will try that later. Thanks for the replay

---

<div class="post-metadata">

### Author: ![Edwin\_Silva](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@Edwin\_Silva](https://meta.discourse.org/u/Edwin_Silva)
#### Post date: [October 18, 2018, 10:03pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/16 "2018-10-18T22:03:41Z")

</div>

It worked. Thanks man. You a lifesaver

---

<div class="post-metadata">

### Author: ![slim](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@slim](https://meta.discourse.org/u/slim)
#### Post date: [July 19, 2020, 6:41pm UTC](https://meta.discourse.org/t/api-for-changing-category-groups/99857/17 "2020-07-19T18:41:56Z")

</div>

Hi @Edwin_Silva and @mikechristopher

I’m trying to apply the lessons here, but failing.  
In my case, instead of CREATING a category with group access, I’m ADDING a group to an EXISTING category.

When I apply the lessons above, I get an error saying that the subcategories don’t have access to their parent category.

If I specify a permissions[group\_name] for every single group name that the category already has, then I don’t get an error. So I at least know what the problem is. It think I’m setting just one permission and removing the rest.

Now I’m wondering if it’s possible to just add ONE new group permission without having to set the entire permission set.

Would you be willing to help?

slim
