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

泄露秘密 提交于 2019-11-30 17:27:04

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.

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

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

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:

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!