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

老子叫甜甜 提交于 2019-11-30 00:34:16

问题


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?


回答1:


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.




回答2:


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




回答3:


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




回答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:




回答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 !




回答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.




回答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



来源:https://stackoverflow.com/questions/29392407/how-to-get-a-slack-user-by-email-using-users-info-api

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