We Want to Hear From You! What Do You Want to See on the Community? Tell us here!

Forum Discussion

jerry14's avatar
jerry14
Explorer | Level 4
4 years ago

API - Getting owner information of a file that is not shared

Hi - I am trying to get owner information of a file that is not shared.  I tried the below - 

 

FileMetadata fileMetadata = (FileMetadata) dbxTeamClient.asAdmin(adminId).files().getMetadata(fileId);

 

But FileMetadata doesn't seem to have this information.  For shared files/folders, I am able to get same using sharing/list_file_members API. But the same API fails when  a non-shared fileId is passed to it.

 

This is for Team Space configuration and I am accessing the file with Admin credentials

 

Thanks

6 Replies

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    4 years ago

    Hi jerry14,

    You cannot get such information within FileMetadata just because there is no such info within. 🙂 You correctly referred to SharedFileMembers (despite indirectly), where you can get desired info. Such a result you can receive from DbxUserSharingRequests.listFileMembers(java.lang.String file).


    jerry14 wrote:

    ... But the same API fails when  a non-shared fileId is passed to it.

    ...


    To be honest I have no idea what you are talking about here. 🤷 It's working as expected. What fails actually? 🤔 Can you post some code snippet able to reproduce the issue in a stable way? Describe expected output, actual output, and what exactly confuses you.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    4 years ago

    Files that aren't shared won't be explicitly listed as having an owner. Files that aren't shared are just implicitly considered to be owned by the user account that contains the files.

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    4 years ago

    Greg-DB wrote:

    Files that aren't shared won't be explicitly listed as having sharing information or an owner. ...


    Yes, but this doesn't mean that listing shared members of particular file (even non shared) should fail! In such a case the owner will be the only listed user (or should be at least). Am I wrong?

    By the way I asked already jerry14, to provide some additional information, but spam filter seems caught my post (for whatever reason).

  • jerry14's avatar
    jerry14
    Explorer | Level 4
    4 years ago

    Thanks for the response.  In that case, whats the best way to find the owner information using the APIs? I checked the metadata and other file related APIs to see if I can get the information. I couldn't find any or I must have missed something.  I need this because I am accessing files that belongs to different members using admin credentials and the connected member (admin member) is not the owner of the file.

     

     

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    4 years ago

    If you've received a file ID from somewhere, it may be best to record the account that was associated when receiving that file ID. For example, if you are reading from the event log, and are taking the file ID from events about files there, you should also read out and save the account ID for the associated account from the event information.

     

    If you only have the file ID though and don't know what account on the team it corresponds to, you should be able to get the account ID from FileSharingInfo.getModifiedBy() in the returned FileMetadata.getSharingInfo(), e.g., on the FileMetadata returned by getMetadata as in your example, even if it's not in a shared/team folder. (The "Sharing" term is a bit of a misnomer in this case; it would be set though because you're accessing the file information from another account via the admin access.)

     

    You can look up the account information for the account ID using getAccount. You'd need to use asMember for that instead of asAdmin though.


    The team space itself is just considered owned by the team, not a specific user.

  • jerry14's avatar
    jerry14
    Explorer | Level 4
    4 years ago

    Its not an issue, but I was looking for the right/best way to find users/groups that has access to a list of files. 

     

    Below are the steps:

     

    a.  The list of files (fileIds) in a Business Account (with Teamspace config) is fetched first using list_folder/list_folder_continue APIs. The authenticating user is Admin for the business account. The list includes private (non shared) files as well belonging different members in the account.

    b.  Now, with each of these fileIds, I was trying to fetch sharing info with the sharing/list_file_members API.  I was able to get details for all files in team/shared folders with this. 

    c.  As sharing info was not available for private files, I was looking at Metadata for "owner" information, however thats not directly available in Metadata or sharing info. 

     

    I followed what Greg-DB suggested, and below are the 3 cases depending on the file ownership/sharing status

     

    1.   For files in shared/team folders -> sharing/list_file_members API gives the information. No issues here.

    2.  For files that are private and belonging to members other than authenticated user  -> sharing/list_file_members API gives sharing info -> and from that, modified by field gives the account Id. With the account id, I am getting account info and finding the team member id (owner)

    3.  For files that are private and belonging to current authenticated user (in my case, the admin user) -> unlike case (2) sharing info is NULL in the response to sharing/list_file_members. In this case, I already know the admin user's member Id. So, assigning that as the owner.

     

    I am not sure if the approaches followed in (2) and (3) are the right/best way since it involves multiple API calls to get the owner/access information. 

     

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,037 PostsLatest Activity: 6 hours ago
412 Following

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!