Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ Channel Management Events
+------------------------------------+-------------------------------------------------------------------+
| ``removeChannelMember`` | Removing members from channels |
+------------------------------------+-------------------------------------------------------------------+
| ``setChannelMembers`` | Bulk set (replace) channel memberships |
Comment thread
wiggin77 marked this conversation as resolved.
+------------------------------------+-------------------------------------------------------------------+
| ``restoreChannel`` | Restoring deleted channels |
+------------------------------------+-------------------------------------------------------------------+
| ``updateChannel`` | Updating channel information |
Expand Down
40 changes: 40 additions & 0 deletions source/administration-guide/manage/team-channel-members.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,43 @@ A list of all members in a channel is visible to system admins. Members can be a
- Member
- Channel admin
- System admin

Bulk set channel members via the API
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

*Available from Mattermost v11.7*
Comment thread
wiggin77 marked this conversation as resolved.
Outdated

System admins can set the complete membership of a channel in a single API call using ``PUT /api/v4/channels/{channel_id}/members``. The request body is a JSON array of user IDs representing the desired membership. The server computes the diff against the current membership and adds or removes users as needed, leaving existing members untouched.
Comment thread
wiggin77 marked this conversation as resolved.
Outdated

Results are streamed back as NDJSON (``application/x-ndjson``), one line per batch. Each line contains ``added``, ``removed``, and ``errors`` arrays for that batch. Query parameters ``batch_size`` (default 100) and ``batch_delay_ms`` (default 500) control the processing rate.

**Example**

Request (using ``batch_size=2`` and ``batch_delay_ms=200``):

.. code-block:: bash

curl -X PUT \
'https://mattermost.example.com/api/v4/channels/channel123/members?batch_size=2&batch_delay_ms=200' \
-H 'Authorization: Bearer <token>' \
-H 'Content-Type: application/json' \
-d '["user_id_1", "user_id_2", "user_id_3", "user_id_4"]'

Streamed NDJSON response (one JSON object per line, one line per batch):

.. code-block:: text

{"added":[],"removed":["user_id_5","user_id_6"],"errors":[]}
{"added":["user_id_3","user_id_4"],"removed":[],"errors":[]}
{"added":[],"removed":[],"errors":[{"user_id":"user_id_7","error":"user is not a member of the team"}]}

In this example, ``user_id_1`` and ``user_id_2`` were already members (no-op), ``user_id_5`` and ``user_id_6`` were removed, ``user_id_3`` and ``user_id_4`` were added, and ``user_id_7`` could not be added because the user is not on the team.
Comment thread
wiggin77 marked this conversation as resolved.
Outdated

Restrictions:

- Requires ``manage_system`` permission (system admin only).
- DM/GM and group-constrained channels are rejected.
- Private channels cannot be emptied entirely.
- Request body is limited to 12 MB.

See the `API documentation <https://api.mattermost.com/#tag/channels/operation/SetChannelMembers>`__ for full details.
Loading