Skip to content

Instantly share code, notes, and snippets.

@dommmel
Created May 25, 2016 14:40
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save dommmel/6726a2cfef07bb58cc03ba7355c148ba to your computer and use it in GitHub Desktop.
Save dommmel/6726a2cfef07bb58cc03ba7355c148ba to your computer and use it in GitHub Desktop.
Zapier Code to auto invite users to slack
var slackTeam = "YOUR_SLACK_TEAM_NAME ";
var token = 'YOUR_ADMIN_TEST_TOKEN';
// A test token will suffice.
// You can generate one at https://api.slack.com/docs/oauth-test-tokens
// Just make sure that the user issuing the test token is an admin.
var url = 'https://'+ slackTeam + '.slack.com/api/users.admin.invite';
fetch(url, {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: "token="+ token + "&email=" + input.email
})
.then(function(res) {
return res.text();
})
.then(function(body) {
var output = {rawHTML: body};
callback(null, output);
})
.catch(callback);
@hashimwarren
Copy link

Wow! It worked! Thanks for sharing your work.

@dsiles
Copy link

dsiles commented Sep 20, 2016

Perfect solution... much better than others I have been trying. Thank you!

@pluthena
Copy link

Works! Thank you! Suggested tweaks to invite as a single channel guest to a specified channel?

@skylartaylor
Copy link

This worked perfectly! Thank you so much!

@Rustonian
Copy link

@pluthena I need the same thing!

@EvgenSchastnyy
Copy link

How to use this code in Zapier?

@okrg
Copy link

okrg commented May 25, 2018

@EvgenSchastnyy Add the step named "Code", it is a built-in app by Zapier. Select JS, create the input data variable named email and map it to the email address from your trigger step.

Then paste the above JS code, but it seems the email variable should be named inputData.email to match how the current version of Zapier Code input data is named.

@OneKostas
Copy link

Many thanks for the solution!

@NickEubanks
Copy link

Hey @dommmel any chance you have an updated script since Slack deprecated workspace tokens and now requires OAuth authentication flow?

@thalesbros
Copy link

Did anyone find out how to do this since the legacy tokens are now disabled?

Copy link

ghost commented Nov 14, 2020

Any update guys?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment