Slack API team invitation
Invite new users via API
There is an undocumented method in the Slack API that allows you to programmatically invite new users to your Slack workspace:
- method name:
users.admin.invite
- arguments:
token
,email
,channels
- token: your slack API "test" token (required)
- email: email address, e.g.
[email protected]
(required) - channels: comma separated list of channels the new user will auto-join. channels are specified by ID. e.g.
channels=C000000001,C000000002
(optional)
full example:
https://slack.com/api/users.admin.invite?token=XXX&[email protected]&channels=C000000001,C000000002
Note that this API method only works with legacy type tokens.
I started documenting the "undocumented" Slack API methods I know about including users.admin.invite
. Check out the documentation on github.
Create new users via API
Alternatively there is an endpoint in the SCIM API to directly create new users:
POST /Users
However the SCIM API with all its endpoints is only available to Slack workspaces on the Plus plan or Enterprise Grid.
Important Update
Slack has decided to remove legacy tokens from their API. It will no longer be possible to create new legacy tokens as of May 5th, 2020 (Source). If you have a working legacy token you should be able to continue using the undocumented API methods, but new users will not. Please take this into consideration when deciding about using any of the methods from this repo in your apps.
Sadly the undocumented endpoint for inviting new users (users.admin.invite
) is no longer available for new workspaces, because it requires a legacy token.
But there is an alternative solution.
What the undocumented endpoint mostly does is sending an email to a specified email address containing an invitation link for your workspace. Here is how you can reproduce that functionality:
- Manually create an invitation link for your workspace
- Send an email containing the invitation link to new users
Note that invitation links expires after 2.000 invites, so you need a way to count usage and being notified when they need to be replaced.