Reputation: 152
I invited new user into slack team using slack API method users.admin.invite
. I need to join him into some public and some private channels. Channels I gave as params in my inviting request, but with private channels I have trouble. It is not channels and it have another method to join user into it.
Method groups.invite
need userId to join him.
Is it possible to add this user in the slack private channels (groups) using slack API?
Upvotes: 0
Views: 2515
Reputation: 32837
The undocumented API method users.admin.invite
has a channels
property, where you can specify a list of IDs for the channels your want a new user to be automatically invited to.
This also works with private channels (I just tested it to confirm). All you need to do is to specify a private channel ID instead, which start with a G
instead of a C
.
You can use the API method groups.list
to get the correct private channel ID. (private channels are called groups in the Slack API)
Example request:
https://slack.com/api/users.admin.invite?token=TOKEN&[email protected]&channels=G12345678
If you still getting errors using this approach than its most likely due to other issues, e.g. Slack does not recognize the email address or your access token does not have the admin right.
For more details please see the unofficial documentation of users.admin.invite
on github, which I have updated accordingly.
Upvotes: 3
Reputation: 21
Seems like this API endpoint isn't currently documented by Slack because it's still in development and could change in the future(which may be what you're running into now). Here's a link to a github issue talking more about it. https://github.com/slackhq/slack-api-docs/issues/30
I was able to find a github with documentation for the undocumented slack API endpoints, but those could have changed since they're not official https://github.com/ErikKalkoken/slackApiDoc/blob/master/users.admin.invite.md
From these unofficial API documentation it seems like you'll have to pass in the channelID instead of the channel name. To get channel IDs you'll just need to call the channels.list end point
Upvotes: 2