Search code examples
apislackslack-api

Inviting new user to private channel after inviting him by Slack API


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?


Solution

  • 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.