We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

deeptir94's avatar
deeptir94
Explorer | Level 4
3 months ago

API to upload files to folders outside of user account folder

Hello,

I need to upload files using API to a folder that is outside of my current user account (the user ID I’m logged in with). 

However, when using the API, the folder structure is being created within my user folder instead of uploading to the existing target folder. How can I upload files to these other folders?

For example:

  • The folder labeled with "svc" is my user folder, where the files are currently being uploaded. I assume this is my root folder.
  • "Business Service" is the target folder where I want to upload the files.

 

Thanks

 

  • iNeil's avatar
    iNeil
    Icon for Dropbox Engineer rankDropbox Engineer
    Hello @deeptir94,

    As mentioned by Здравко, by default, API calls to the Dropbox API operate within the "member folder" of the connected account. You can configure the API calls to operate in the team space that is outside of the "member folder" by setting the "Dropbox-API-Path-Root" header in your Dropbox API request.
     
    Below I have provided an example "Dropbox-API-Path-Root" header value to access the team space:
     
    Dropbox-Api-Path-Root: {".tag": "root", "root": "YOUR_ROOT_NAMESPACE_ID"}
     
    You should be able to identify the root_namespace_id by executing the 2/users/get_current_account endpoint. You can also test the 2/users/get_current_account endpoint using our Dropbox API explorer.
     
    For further information, please review the following links:

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

    Hi @deeptir94,

    Your issue is related to the fact that API default access start from users home folder. While for individual users their home is their account root, for business user home folder (the your folder starting with "svc" as seems) is not account root (or at least not mandatory to be - in most cases these days, it is NOT). In business accounts, you need to set the account root explicitly to override the default home folder when you need (like in your case). This happens using HTTP header "Dropbox-API-Path-Root" set to appropriate namespace id (the root namespace id in your case, but you can set any other namespace id if you want that namespace to be your access root). Take a look here (and linked resources there) for additional details. Use appropriate method if you use some of the supported SDKs.

    Hope this helps.

    • deeptir94's avatar
      deeptir94
      Explorer | Level 4

      Hello, thanks for your reply.

      I am still not sure how to fetch the namespace id for my folder. The API calls return information regarding the default root folder.

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

        In most cases, setting the account root namespace id is enough since in such a way you can access everything accessible to particular user. So maybe it's the best way for you too. If you want to select from other available namespaces, you can enumerate them using /2/team/namespaces/list/continue.

        Hope this sheds a light.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,877 PostsLatest Activity: 12 months ago
326 Following

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!