Skip to content

Instantly share code, notes, and snippets.

@anteos
Forked from dommmel/invite_to_slack.js
Last active October 3, 2017 12:12
Show Gist options
  • Save anteos/ff250d8d3cd7bf2a9485d4593bc22a8e to your computer and use it in GitHub Desktop.
Save anteos/ff250d8d3cd7bf2a9485d4593bc22a8e to your computer and use it in GitHub Desktop.
Zapier Code to auto invite users to slack
//added channels, first and last_name parameters
// CHANNEL_ID is visible at the end of the channel URL
var slackTeam = "YOUR_SLACK_TEAM_NAME ";
var token = 'YOUR_ADMIN_TEST_TOKEN';
var channels = "CHANNEL_ID";
// 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 + "&channels=" + channels + "&first_name=" + input.first_name + "&last_name=" + input.last_name
})
.then(function(res) {
return res.text();
})
.then(function(body) {
var output = {rawHTML: body};
callback(null, output);
})
.catch(callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment