Is there any SDK ( Java ) that allowes to search an user ( External or managed ) based on login?

新規投稿

コメント

13件のコメント

  • Bibek

    Hi ,

    I am not sure about the specifics about the  Java SDK. But the vanilla API way of doing is to do  as follows:

     

    https://api.box.com/2.0/users?filter_term=***@example.com

     

    it will return only user that matches with the "filter_term". "filter_term" could be either login or email.  It will return multiple users if you user filter_term like   "filter_term=jon". It would return results for jon,jonny, jones, jon1 etc. So, I would prefer to search via Email address so it will only return 1 result if matched. 

     

    Note: Only Enterprise Admin will be able to do it. PLease make sure about it.

    Hope this helps. 

     

    thanks,

    Bibek

     

    0
    コメントアクション Permalink
  • Murtza

    is correct!

     

    Line 161 of the BoxUser class in the Java SDK shows the method signature to search for a user with their email address. 

     

    Line 42 of the BoxUserTest class in the Java SDK shows an example of how to call this method.

    0
    コメントアクション Permalink
  • Box Product Support

    Thank you for your suggestion, Bibek.

    0
    コメントアクション Permalink
  • Box Product Support

    Thank you Murtza for your response. I have following followup.

    1.

    When I make a call using BoxUser.getAllEnterpriseUsers with filterTerm and fields it only checks against managed users, which is a default behaviour and works fine. But I need to check if passed in login is external or not. The method, BoxUser.getAllEnterpriseUsers(api, filterTerm, fields), does not seem to have a way to provide "user_type" which could be all, managed, external. Can you please let me know how I can do this via SDK. Is there any other method to do so?

     

    2. I saw

     

     public static Iterable getExternalUsers(final BoxAPIConnection api, final String filterTerm,
              final String... fields) {
            return getUsersInfoForType(api, filterTerm, "external", fields);
        }

    on BoxUser class line 177. But it looks like it is not exposed. I am using "box-java-sdk" version "2.1.1". It will be nice if I could call above method directly. Am I missing anything here? is there a way to do so ?

    Please advise.

     

    Thank you

    MCB

     

    0
    コメントアクション Permalink
  • Box Product Support

    Murtza,

     

    Although I had 2.1.1 java-sdk it did not had the method. I got a latest copy fro git and I can see the method.Looks like it added in last 2/3 months. I am going to use it and give it a try. I will let yo know how it goes.

     

    Thanks

    mcb

     

    0
    コメントアクション Permalink
  • Box Product Support

    Hi,

     

    Thanks for you help Murtza and Bibek. I just tested latest java sdk form Git using

    public static Iterable getExternalUsers(BoxAPIConnection api,
                                                          String filterTerm,
                                                          String... fields)

    It seems to work fine as stated in desc; which is

    "Gets a limited set of information about an external user. (A user collaborating on content owned by the enterprise)"

    Basically it is checking external login that is tied to an enterprise acount and does not find they are not tied to an account yet. But I need to check if the login is there in the Box domain as whole. I need to do this because my use case need to check for incmoing login and if this login is already in there even outside our enterprise acount then add them as collaborator else need to create these login wihtin ours enterprise as managed users. So how will be able to check if login is already there in whole of box ? 

    Any suggestion?

     

    Thank You

    mcb

     

     

    0
    コメントアクション Permalink
  • Murtza

     The getAllEnterpriseOrExternalUsers method should help for your use case. Here is the method signature from the BoxUser class in the Java SDK.

    0
    コメントアクション Permalink
  • Box Product Support

    , Thank you very much for your reponse. I tried below

     

    		final String filterTerm = "***@example.com";
    	        final String name1 = "Sample user";
    
    	        Iterable searchUserResult
    			=BoxUser.getAllEnterpriseOrExternalUsers(api, filterTerm, "login", "email");
    
    			//searchUserResult.
    			ArrayList searchUserResultAlist= new ArrayList();
    			searchUserResult.forEach(searchUserResultAlist::add);
    			
    			log.info("Size of match returned="+searchUserResultAlist.size());
    			
    			if ( searchUserResultAlist.size()>0 ) {
    				log.info("Id="+ searchUserResultAlist.get(0).getID() );
    				log.info("Login="+ searchUserResultAlist.get(0).getLogin() );
    			}

    But still the method only checked within current "organization". If it is in other organization it does not find it. In my use case the login provided could be in other organization as well. So I need to search the whole box organization.

     

    In above case "***@example.com" is there in box in another org but no in the account I use. And it does not find it. If I provide any managed and/or external login that is withing the account it finds it. Please advise how to search these outer org login existence ?

     

    Thank You

    mcb

     

     

    0
    コメントアクション Permalink
  • Bibek

    Hi ,

    I believe when you use https://api.box.com/2.0/users?filter_term=***@example.com&user_type=external  API call, it will only work for those external users who are the "external" collaborators in your company.

    So, whoever external users that you are able to view from the Admin portal, this API works and will gives you the minor detail about those users. 

     

    But if you want to get other users who doesn't even have any collaboration yet in your company then, it is not possible to get.  Only Box will be able to provide you details but in this case this would be violation of privacy to obtain account information for external account if it is not associated with your company as an external account. 

     

    thanks,

    Bibek

    0
    コメントアクション Permalink
  • Box Product Support

    HI ,

     

    Thank you for your response. The behaviour is exactly what I got from the code.

     

    I am not looking for detail info on those external users. Since the use case I have is to add users as managed users to our account if they do not already in external organizations. We do not need to know detail on those, just to check if login exists or not. As simple as that, If they exists in external orgs then we will either have to invite them to our org as an collaborator. Checking if login/username exists in the over all box domain should not be privacy issue at all. If the feature is not there then it separate thing. But it will be very handy in several use cases.

     

    Thoughts?

     

    Thanks

    mcb 

    0
    コメントアクション Permalink
  • Bibek

    Hi ,

     I don't think Box API has a feature to check that yet. 

    But I think what you could do is  - since you need to create a managed account for the users. You could actually call the create user API without checking if their account exists. If they already have box account associated with that particular email address then you will get error such as "user_login_already_used".  

     

    e.g.

    {
    "type": "error",
    "status": 409,
    "code": "user_login_already_used",
    "help_url": "http://developers.box.com/docs/#errors",
    "message": "User with the specified login already exists",
    "request_id": "requestid"
    }

     

    Let me know if this makes sense.

     

    thanks,

    Bibek

    0
    コメントアクション Permalink
  • Box Product Support

    Hi

    Yes, it does make sense and seems like this is the only way to do it for now.

     

    Thanks

    mcb

     

    0
    コメントアクション Permalink
  • pgoldweic

    Just wanted to bring up the fact that it would be great if the filtering that the API allows was a little more sophisticated. Currently, the filtering only compares the string you supply against a prefix of the name or login. Ideally, you'd be able to tell the API the type of match you'd like to see (e.g. contains -which subsumes the current 'prefix' mode, suffix, etc.), equals, etc.). Are there any plans to add this capability?

    0
    コメントアクション Permalink

サインインしてコメントを残してください。