# \[Solved\] Make Categories the same for all Members

**URL:** <https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266>\
**Category:** Troubleshooting\
**Created:** [March 3, 2023, 4:39pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266 "2023-03-03T16:39:55Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/akito/32/4090_2.png) [@Akito](https://forum.mattermost.com/u/Akito)\
**Post date:** [March 3, 2023, 4:39pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/1 "2023-03-03T16:39:55Z")

</div>

```auto
Mattermost Version: 7.5.2
Database Schema Version: 95
Database: postgres

```

How does the Administrator make categories the same for everyone?

For example, if I put in Channel 1, Channel 2 & Channel 3 in Category My Category, then I want new member to have this category, including the three channels, visible in the sidebar.

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [March 3, 2023, 4:55pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/2 "2023-03-03T16:55:46Z")

</div>

Hey Akito,

You can do that with an onboardingscript which creates the categories and adds the channels for the user in the sidebar via the API, but that requires you to know when people join or to prepare their accounts before first use, not sure if this is an option.

There’s a feature which never really worked for me and is called “Default channels” which can be used to add all new users to a list of channels you specify in the server configuration. Using this feature combined with the feature “Channel actions”, you can automatically put the channels into categories for the users, at least during provisioning, but the users can change that, so you cannot enforce this configuration on them if they want to change it (or leave channels, f.ex.) and they can also rename their categories.

Would something like that help or do you require more control on what your users see and can do to their view?

---

<div class="post-metadata">

**Author:** ![Akito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/akito/32/4090_2.png) [@Akito](https://forum.mattermost.com/u/Akito)\
**Post date:** [March 3, 2023, 8:46pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/3 "2023-03-03T20:46:09Z")

</div>

> [@agriesser](#):
>
> onboardingscript

Was searching for that, but I did not find anything.

> <https://github.com/mattermost/mattermost-plugin-welcomebot/blob/master/README.md#example>

What the Welcome Bot can do, is very useful. If it only would create categories, as well.

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [March 4, 2023, 3:32pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/4 "2023-03-04T15:32:35Z")

</div>

The onboardingscript is nothing you can find online, it’s more a hint that you would need something like that.  
I wrote a script for someone on the community server some time ago, which should give you an idea on how to proceed. If not, let me know how we can fine-tune it to your needs:

```bash
#!/bin/bash

# space separated list of channels to add for each user
CHANNELS="writing_work lab_work cyber_342w_homework_help general_ist_homework_help off_topic"
# team to add the users to
TEAM="cyber-342w"
# the maildomain added to the username
MAILDOMAIN="school.edu"
# mmctl command
MMCTL="mmctl --local"
# password to be used for all accounts. Leave empty and set PWLEN > 0 if you want passwords to be auto-generated
PASSWORD=""
PWLEN=16
# set to empty string if you want to actually run the commands, set to "echo" if you just want to see what woule be done
DEBUG="echo"

# first parameter of the script will be the file to read the input data from
# if no parameter is given or if the file cannot be found, fail
if [-z "$1"] || ! [-f "$1"]; then
  echo "input file $1 not found."
  exit 1
fi

while read line; do
  # split the input line by space into parts
  IFS=" " read -r -a PARTS <<< "$line"
  # generate random password if requested
  ["$PWLEN" -gt "0"] && PASSWORD=$(makepasswd --chars=$PWLEN)
  # create the user account
  $DEBUG $MMCTL user create --email "${PARTS[0]}@$MAILDOMAIN" --email-verified --firstname ${PARTS[1]} --lastname ${PARTS[2]} --locale en --password $PASSWORD --username ${PARTS[0]}
  # add it to all mentioned channels
  for channel in $CHANNELS; do
    $DEBUG $MMCTL channel users add $TEAM:$channel ${PARTS[0]}
  done
  # output user + password for copy/pasting it to the users
  echo "${PARTS[0]} / $PASSWORD"
done < "$1"

```

This script reads in a CSV of users to create and sets them up automatically and also adds them to a list of predefined channels.  
The categories can be done using channel actions, as I said - so in your existing channels, you can click on the channel and choose “Channel actions” which will give you the following modal:

 ![grafik](https://us1.discourse-cdn.com/flex020/uploads/mattermost/original/2X/6/6b720271daf3e115a6878fe0aa72b8f73425f1d9.png)

Here you can specify the category to add this channel to and when the category does not exist, it will be created on the fly for the user that joined the channel.

---

<div class="post-metadata">

**Author:** ![Akito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/akito/32/4090_2.png) [@Akito](https://forum.mattermost.com/u/Akito)\
**Post date:** [March 5, 2023, 1:07am UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/5 "2023-03-05T01:07:32Z")

</div>

The script seems very helpful. Thank you.

Meanwhile, I checked out the [API Documentation](https://api.mattermost.com/) and simply could not find a way to add a channel to a specific category or assign a category to a specific channel.

Am I missing something?

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [March 5, 2023, 8:56am UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/6 "2023-03-05T08:56:31Z")

</div>

That’s because a channel does not belong to a sidebar category. The categories are part of the user’s view, so every user could have his own categories, that’s why you cannot configure that by channel.

The API calls you’re looking for are [CreateSidebarCategoryForTeamForUser](https://api.mattermost.com/#tag/channels/operation/CreateSidebarCategoryForTeamForUser) et al.

---

<div class="post-metadata">

**Author:** ![Akito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/akito/32/4090_2.png) [@Akito](https://forum.mattermost.com/u/Akito)\
**Post date:** [March 5, 2023, 3:42pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/7 "2023-03-05T15:42:52Z")

</div>

> [@agriesser](#):
>
> That’s because a channel does not belong to a sidebar category. The categories are part of the user’s view, so every user could have his own categories, that’s why you cannot configure that by channel.

Yes, I understand, but there must be a way to move a channel into a specific category, for that particular user. The database has some kind of connection there, as well, to know, which channel ought to be shown under which category.

> [@agriesser](#):
>
> The API calls you’re looking for are [CreateSidebarCategoryForTeamForUser](https://api.mattermost.com/#tag/channels/operation/CreateSidebarCategoryForTeamForUser) et al.

Seen that one, but it does not let me assign channels to it, by user or something equivalent to that functionality. 😕

---

<div class="post-metadata">

**Author:** ![Akito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/akito/32/4090_2.png) [@Akito](https://forum.mattermost.com/u/Akito)\
**Post date:** [March 6, 2023, 12:41am UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/8 "2023-03-06T00:41:30Z")

</div>

> [@Akito](#):
>
> Seen that one, but it does not let me assign channels to it, by user or something equivalent to that functionality. 😕

Okay, so the only place I found anything related to what I am seeking is in [GetSidebarCategoriesForTeamForUser](https://api.mattermost.com/#tag/channels/operation/GetSidebarCategoriesForTeamForUser).

### Example Output

```json
[
  {
    "order": [
      "string"
    ],
    "categories": [
      {
        "id": "string",
        "user_id": "string",
        "team_id": "string",
        "display_name": "string",
        "type": "channels",
        "channel_ids": [
          "string"
        ]
      }
    ]
  }
]

```

Which displays the assigned channel IDs.

Now, I need the same thing, except the other way around. I want to send a payload, patching an existing sidebar category to include all channel IDs from the provided array.

---

<div class="post-metadata">

**Author:** ![Akito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/akito/32/4090_2.png) [@Akito](https://forum.mattermost.com/u/Akito)\
**Post date:** [March 6, 2023, 1:29am UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/9 "2023-03-06T01:29:02Z")

</div>

Never trust the official API documentation!

As it turns out, providing the channel IDs via [UpdateSidebarCategoriesForTeamForUser](https://api.mattermost.com/#tag/channels/operation/UpdateSidebarCategoriesForTeamForUser) was already possible – it’s just, that the API documentation is incomplete.

So, if anyone wants to move a channel from one category to another, one must fetch both categories, remove the channel IDs in question from the current category & add them to the channel ID list of the new category. Then, PUT the category array to `https://your-mattermost-url.com/api/v4/users/{user_id}/teams/{team_id}/channels/categories` & the channel is moved, after the user reloaded the Mattermost page in the browser.

## Nu Definition

```nu
#!/usr/bin/nu

def content_type [] { "application/json" }
def url_base [] { "https://your-mattermost-url.com/api/v4/" }
def url_user_sidebar_categories [team_id: string user_id: string] { $"(url_base)users/($user_id)/teams/($team_id)/channels/categories" }

# Update User's Sidebar Categories
# https://api.mattermost.com/#tag/channels/operation/UpdateSidebarCategoriesForTeamForUser
export def updateUsersSidebarCategories [
  token: string # https://docs.mattermost.com/developer/personal-access-tokens.html#creating-a-personal-access-token
  team_id: string
  user_id: string
  body: string
] {
  # PUT to API
  (
    http put
      -H [Authorization $"Bearer ($token)"]
      -H [Accept content_type]
      $"(url_user_sidebar_categories $team_id $user_id)"
      $body
  )
}

```

##### Currently only works with Nu 0.77.0, which is not yet released, at the time of writing.

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [March 6, 2023, 5:27am UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/10 "2023-03-06T05:27:38Z")

</div>

Thanks for the hint about the documentation, I cannot see the channel\_id in your example. Are you saying that the payload in the documentation

```json
[
  {
    "id": "string",
    "user_id": "string",
    "team_id": "string",
    "display_name": "string",
    "type": "channels"
  }
]

```

does also support a `channel_id` like this`?

```json
[
  {
    "id": "string",
    "user_id": "string",
    "team_id": "string",
    "display_name": "string",
    "channel_id": "string",
    "type": "channels"
  }
]

```

Also, can you send me a link to the `nu` tool you’re referencing here? I’m unable to find it on the net.

---

<div class="post-metadata">

**Author:** ![Akito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/akito/32/4090_2.png) [@Akito](https://forum.mattermost.com/u/Akito)\
**Post date:** [March 17, 2023, 7:51pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/11 "2023-03-17T19:51:48Z")

</div>

@agriesser

I’m back.

Had decided to dive a bit deeper into this issue.

> <https://github.com/mattermost/mattermost/issues/22445>
>
> \#### Summary
> When creating a new Category via \[CreateSidebarCategoryForTeamForU…ser\](https://api.mattermost.com/#tag/channels/operation/CreateSidebarCategoryForTeamForUser) with the following payload
> 
> \`\`\`json
> {
> "user\_id": "user\_id",
> "team\_id": "team\_id",
> "display\_name": "My Category",
> "type": "custom",
> "sorting": "manual"
> }
> \`\`\`
> 
> then retrieving all the categories from the user via \[GetSidebarCategoriesForTeamForUser\](https://api.mattermost.com/#tag/channels/operation/GetSidebarCategoriesForTeamForUser) results in the previously created Category containing an empty string as the value for \`"sorting"\` in the returned array of Category objects.
> 
> \#### Steps to reproduce
> 1. Create a new Category via \[CreateSidebarCategoryForTeamForUser\](https://api.mattermost.com/#tag/channels/operation/CreateSidebarCategoryForTeamForUser) with \`"sorting": "manual"\`.
> 2. Retrieve all categories from the user via \[GetSidebarCategoriesForTeamForUser\](https://api.mattermost.com/#tag/channels/operation/GetSidebarCategoriesForTeamForUser) and notice, how \`"sorting": ""\`.
> 
> \#### Expected behavior
> Sorting attribute should be reported, correctly.
> 
> \#### Observed behavior (that appears unintentional) 
> The API wasn't aware of this issue.
> 
> In the GUI, the sorting was set to "manual". It might also be the case, that during the creation of a category the \`sorting\` attribute is ignored, which would be something to fix, either way.
> 
> \#### Workaround
> Update User's Sidebar Categories via \[UpdateSidebarCategoryForTeamForUser\](https://api.mattermost.com/#tag/channels/operation/UpdateSidebarCategoryForTeamForUser) or \[UpdateSidebarCategoriesForTeamForUser\](https://api.mattermost.com/#tag/channels/operation/UpdateSidebarCategoriesForTeamForUser) with \`"sorting": "manual"\` re-added, after retrieving the current category state via \[GetSidebarCategoriesForTeamForUser\](https://api.mattermost.com/#tag/channels/operation/GetSidebarCategoriesForTeamForUser).

This is my almost final result.

> **[GitHub - theAkito/mattermostwebhookhandler: Handle outgoing Mattermost...](https://github.com/theAkito/mattermostwebhookhandler)**
>
> Handle outgoing Mattermost Webhooks through a server for automation purposes. - GitHub - theAkito/mattermostwebhookhandler: Handle outgoing Mattermost Webhooks through a server for automation purpo...

> [@agriesser](#):
>
> can you send me a link to the `nu` tool you’re referencing here?

> **[Nushell](https://www.nushell.sh/)**
>
> A new type of shell.

---

<div class="post-metadata">

**Author:** ![iqoqi](https://avatars.discourse-cdn.com/v4/letter/i/f1d935/32.png) [@iqoqi](https://forum.mattermost.com/u/iqoqi)\
**Post date:** [March 30, 2023, 12:55pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/12 "2023-03-30T12:55:53Z")

</div>

Sorry to butt in, but is it possible to have such a function as a feature request?  
We would need that too.

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [April 3, 2023, 4:03am UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/13 "2023-04-03T04:03:25Z")

</div>

Hi @iqoqi and welcome to the Mattermost forums!

The more people request such a feature on Mattermost’s product board, the more likely we will see it, so please raise your voice on [https://mattermost.com/suggestions](https://mattermost.com/suggestions) for such a feature.

---

<div class="post-metadata">

**Author:** ![tralston](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/tralston/32/7289_2.png) [@tralston](https://forum.mattermost.com/u/tralston)\
**Post date:** [March 11, 2024, 7:29pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/14 "2024-03-11T19:29:53Z")

</div>

@agriesser @Akito  
Based on a recent support ticket, I was told that this API exists, but looks like it hasn’t been documented yet. The “Channel Actions” mentioned [here](https://forum.mattermost.com/t/make-categories-the-same-for-all-members/15266/4) can be done graphically, but to do it via API you need to use this:

`https:/<url>/plugins/playbooks/api/v0/actions/channels/<channel id>`  
with a JSON payload of:

```json
{
    "enabled":true,
    "payload":
        {
            "category_name":"Testing01"
        },
    "channel_id":"sd9sxu89c7d5igqchqxdrryoyw",
    "action_type":"categorize_channel",
    "trigger_type":"new_member_joins"
}

```

I tested this and it works for me (cloud).

---

<div class="post-metadata">

**Author:** ![ylluminate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/ylluminate/32/2253_2.png) [@ylluminate](https://forum.mattermost.com/u/ylluminate)\
**Post date:** [December 17, 2024, 7:27pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/15 "2024-12-17T19:27:44Z")

</div>

This 100% most certainly needs to be an integrated feature. Recently ran into a problem where new users to Mattermost have become angry with Mattermost for having “too many channels” in a team. It’s created a schism where there has been a huge push to migrate away from Mattermost and other strange things. Largely due to misunderstanding, but ultimately it boils down to ignorance / user inability to understand how the system functions - and how Categories work.

If we had Category management built into the system that facilitates ready-made categories and management of existing users’ Categories it would be extremely helpful and would ameliorate a lot of resistance.

---

<div class="post-metadata">

**Author:** ![john.oliver](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/john.oliver/32/6436_2.png) [@john.oliver](https://forum.mattermost.com/u/john.oliver)\
**Post date:** [December 17, 2024, 7:49pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/16 "2024-12-17T19:49:32Z")

</div>

For any given channel, go to Channel Actions (under the drop-down title at the top of the channel):

 ![Screenshot from 2024-12-17_12-48-34](https://us1.discourse-cdn.com/flex020/uploads/mattermost/original/2X/8/8567a74dabe54fe8156df68b856af1a034f0fd9a.png)

 ![Screenshot from 2024-12-17_12-47-50](https://us1.discourse-cdn.com/flex020/uploads/mattermost/original/2X/1/1a752bb96b73c530e10f4e7994fb4384968e8b6a.png)

---

<div class="post-metadata">

**Author:** ![ylluminate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/ylluminate/32/2253_2.png) [@ylluminate](https://forum.mattermost.com/u/ylluminate)\
**Post date:** [December 17, 2024, 8:24pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/18 "2024-12-17T20:24:59Z")

</div>

Thank you very much, this is fascinating and very helpful! I’m not sure how this one slipped by, but this is great @john.oliver.

However, I suppose the feature request must become: please make it possible to add a category if it does not exist for a user and insert this into said category (or into an existing category of the same name) of the user… This should be a simple check box.

---

<div class="post-metadata">

**Author:** ![john.oliver](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/john.oliver/32/6436_2.png) [@john.oliver](https://forum.mattermost.com/u/john.oliver)\
**Post date:** [December 17, 2024, 9:06pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/19 "2024-12-17T21:06:57Z")

</div>

If you do that, new users who join the channel after that action will have the sidebar category added. But users who are already members won’t get it added… that action happens on joining.

---

<div class="post-metadata">

**Author:** ![ylluminate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/ylluminate/32/2253_2.png) [@ylluminate](https://forum.mattermost.com/u/ylluminate)\
**Post date:** [December 17, 2024, 10:10pm UTC](https://forum.mattermost.com/t/solved-make-categories-the-same-for-all-members/15266/20 "2024-12-17T22:10:29Z")

</div>

So I figured out a very clunky, but working, workaround that allows bulk removal + re-adding and selective re-adding for private or non-shotgun (read: all team members are already members) approach:

> [@Mmctl channel user list doesn't exist?](https://forum.mattermost.com/t/mmctl-channel-user-list-doesnt-exist/12715/4):
>
> Just to confirm, the following PostgreSQL psql command-line query “one-liner” works to get channel members (if EnableLocalMode is enabled in config.json; otherwise, you will need to use mmctl auth login): CHANNEL\_NAME="PASTE\_CHANNEL\_NAME\_HERE"; \ DB\_USER="mmuser\_USERNAME"; \ DB\_HOST="DATABASE\_SERVER\_HOSTNAME"; \ DB\_NAME="mattermost\_DATABASE\_NAME"; \ DB\_PASSWORD="YOUR\_PASSWORD"; \ PGPASSWORD="${DB\_PASSWORD}" psql "postgres://${DB\_USER}@${DB\_HOST}/${DB\_NAME}?sslmode=disable&connect\_timeout=10" …
