'How to get a slack user by email using users.info API?

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?



Solution 1:[1]

Yes!

https://slack.com/api/users.lookupByEmail

Using this we can find a user if email id is available.

More : https://api.slack.com/methods/users.lookupByEmail

Solution 2:[2]

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.

Solution 3:[3]

An undocumented API can do this job: https://slack.com/api/auth.findUser?team=&email=&token=xoxp-XXXXXXXXX

Solution 4:[4]

If this is being done on behalf of a Slack slash command, one can configure the command to expand @username, #channels, etc...

This can be done under the command section of the Slack app. See the following screenshot:

Slack app config: expand usernames and channels

Solution 5:[5]

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 !

Solution 6:[6]

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.

Solution 7:[7]

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

Solution 8:[8]

https://api.slack.com/methods/users.lookupByEmail

enter image description here

POST https://slack.com/api/[email protected]

form-data
token=xoxb-############-#############-$$$$$$$$$$$$$$$$$$$$$$$$

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shree Harsha S
Solution 2 seanrose
Solution 3 sai.xu
Solution 4 sshaw
Solution 5
Solution 6 Nawaz Hussain K
Solution 7 HariKishore K
Solution 8 seunggabi