Forum Discussion

qwesafesa's avatar
qwesafesa
Explorer | Level 3
5 years ago

Use Dropbox API search results to generate dropbox.com file preview urls

We are creating application to help users find their files/folder in dropbox.

 

For searching we used dropbox API route: https://api.dropboxapi.com/2/files/search_v2

 

The goal is: based on results generate proper dropbox.com urls to let user visit dropbox site with opened file.

The issue is: results do not have namespaces in their lower_path or display_path, which leads to not-existing file locations.

 

Javascript Code (using Axios):

const response = await userClient.post(
    '/2/files/search_v2',
    {
      query,
      options: { max_results: limit },
      match_field_options: { include_highlights: true }
    },
    {
      headers: {
        'Content-Type': 'application/json'
      }
    }
  );

  const results = response.data.matches;

Correct behavior:

user is logged in our system via oauth2. User account is simple Dropbox account, and there is basic get started file, its path from API will be 

"path_display": "/Get Started with Dropbox.pdf"

It's okay to generate this link:  https://www.dropbox.com/home?preview=Get+Started+with+Dropbox.pdf

 

Incorrect behavior:

User has Dropbox Business account.

With Dropbox Business, each user has it's own namespace

And the basic Dropbox Business file "Get Started with Dropbox.pdf" url will look something like this

https://www.dropbox.com/home/Username?preview=Get+Started+with+Dropbox.pdf

 

But from the API search request, it's path will be the same 

"path_display": "/Get Started with Dropbox.pdf"

And i see no namespace_id returned in my search query.

 

So, the question is: how to search dropbox files/folders and properly determine, to which namespace they belong?

 

Thanks in advance.

 

 

1 Reply

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

    Unfortunately, the Dropbox API doesn't offer an officially supported way to get or build the private Dropbox web site URL for a file or folder like this, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.

     

    For reference, when calling /2/files/search_v2, the paths in result will be relative to the root for the call (e.g., the user's own folder, or a team space, etc.), which can be specified via 'the 'Dropbox-API-Path-Root' header. If not specified, this is the user's own folder by default. Please refer to the Namespace Guide for more information. When applicable/present, you can also check the returned 'sharing_info' field for information about where a file/folder exists.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

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, Facebook or Instagram.

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!