I’m trying to get all the channels where a user is involved, I have checked the API documentation, Github issues and this forum and I couldn’t find anything related to this.
My purpose is to do this through the REST API (not Websocket, as the integration I’m trying to do is not feasible through them).
So, what I want to accomplish is, given a user ID, get a list of channels which that user belongs to (all type of channels) , is this even possible?
I went through the API documentation and would like to know if you have tried using Get channels for user:
May I know if that works for you? There is also an SQL query for this in case you are interested:
SELECT DISTINCT u.Username, t.DisplayName AS TeamName, c.DisplayName AS ChannelName, cm.SchemeUser AS User, cm.SchemeAdmin AS Admin FROM ChannelMembers AS cm JOIN Channels AS c ON (cm.ChannelId=c.Id) JOIN Users AS u ON (cm.UserId=u.Id) JOIN Teams AS t ON (c.TeamId=t.Id) WHERE u.Username = "<username>";
Thanks for the answer. So yes, I saw this endpoint in the documentation but since it receives a teamId my impression of it was that I wouldn’t get DM channels. Given you recommended using it I gave it a try and was able to accomplish what I wanted.
For people figuring this out in the future here are the endpoints that I used to accomplish getting all the posts for users in all channels.
- Get all teams
- Get all users
- Get channels for user (you will get public channels, private channels and Direct messages where this user is joined)
- Get posts of a channel
I hope this helps anyone later on!