I'm trying to use Slack's users.info
API to retrieve users information, but I need to find users by email, is there a way to do that?
Currently you can only look up users with users.info
by their ID.
An alternative solution to your problem would be to call users.list and filter within your client by the profile.email
for whichever email you're looking for.
Yes!
https://slack.com/api/users.lookupByEmail
Using this we can find a user if email id is available.
An undocumented API can do this job: https://slack.com/api/auth.findUser?team=&email=&token=xoxp-XXXXXXXXX
You should use this scope users:read.email, the users:read is no longer a sufficient scope for email field.
Check this to get more infos: https://api.slack.com/scopes/users:read.email
That's worked for me as wanted !
This was useful for me.
My setup: I am part of an enterprise, so the legacy token
does not have users:read.email
scope to it.
Solution: I created an app with users:read.email
scope and other scopes needed. Got the app approved from my admin, installed the app to my workspace, retrieved the OAuth token, used it with https://slack.com/api/users.lookupByEmail
.
you can get the userid with message.user from main calling method
getUsername(userID).then((output) => { username = output.user.name });
function getUsername(userid){
return new Promise((resolve, reject) => {
//get token from https://api.slack.com/methods/users.info
options.uri = "https://slack.com/api/users.info?token=********&userid=" +userid+ "&pretty=";
rp(options).then(function (body) {
resolve(body);
console.log('Retrieved Info slack --- ' + JSON.stringify(body));
})
.catch(function (err) {
resolve(err);
console.log('aborted - slack ' + JSON.stringify(err));
});
});
}
refer link : https://github.com/hassifow/Slack.API-User.info/blob/master/LambdaFunction.js
来源:https://stackoverflow.com/questions/29392407/how-to-get-a-slack-user-by-email-using-users-info-api