Matttermost, Inc.

Add User to Channel with APIv4 endpoint

I’m trying to add users to a previously created channel using the APIv4 “Add a user” endpoint

The endpoint is specified in this link.

I’m sending a POST HTTP Request to the “https://my-mattermost-url.com/api/v4/channels/{channel_id}/members”, and getting an error like this:

HTTP Request

Response: No team member found for that user ID and team ID.

The channel type is “G” (Group channel).

I’m sure that the user_id sent in the payload is not in that channel and is inside the team that the other users inside the channel are, and yet I’m receiving this error message:

What is wrong with this request? and what is the proper way to use this endpoint?

Hi @mauricio,

That error is unclear in this case, but users cannot be added to group message channels since they work similar to direct message channels. You can instead either create a private channel for those users, which is easier if you’ll want to add/remove users later on, or create a new group channel with all of the users you want

Hi @hmhealey

The problem is that I want to add a user to a channel using the “Add user to channel” endpoint, but (at least from your comment) I think that what is wrong with my approach is that I’m using an incorrect channel type to begin with.

So, if I understand well, the thing is that I need to user “private channels” to make it possible to add users with that endpoint right?

If that is the case, can you give me an example of the correct usage of the “Add user to Channel” endpoint?

@mauricio

Yes, that’s right. The request you were using above is correct, except the channel_id part of http://<server>/api/v4/channels/<channel_id>/members must be for a channel with type “O” (a public channel) or “P” (a private channel). If you don’t already have one of those channels to use, you can use this API route to create one with the correct type.

Hey @mauricio, have you checkout out our APIv4 documentation? It has all of the information that you need to manage channels and channel members.