I am looking for a call which could send a Slack team invitation email to a new user from my application. I searched it in the SlackAPI but I didn't find anything. Is it possible to create an application which would sent invitations on my behalf?
I'm currently using slacker as a Python wrapper, but if there is any better library which provides invitations I can start using it.
Slack API team invitation
20.9k views Asked by warownia1 AtThere are 3 answers
As others have mentioned, there is no documented way of doing this for non-Enterprise plans.
If you want to automate invitations, you have two options:
- You may generate a non-expiring invitation URL and send it to users. This is no different from invitations that Slack sends.
- Use API token that identifies your authentication session.
The latter approach will work only if you are the admin of the workspace.
- Open Slack web app and intercept HTTP requests
- Send an invite using the Slack web app to a test user
- Find HTTP request that mentions
slack.com/api/users.admin.inviteBulk
- Copy
token
parameter value from the HTTP request body.
Now you can use that token
to construct users.admin.inviteBulk
API request using your application.
The downside of this approach is that these tokens eventually expire.
Both methods require manual intervention:
- You need to refresh the URL every 2000 invitations
- You need to refresh the token every 30 days
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.
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:
users.admin.invite
token
,email
,channels
[email protected]
(required)channels=C000000001,C000000002
(optional)full example:
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.