We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.

Forum Discussion

Manmeet Kaur R.'s avatar
Manmeet Kaur R.
New member | Level 1
9 years ago

Using ETL tool's REST utility to download a folder with REST get URL

I wish to use the etl tool's REST utility to download a file from dropbox. I read in the developer docs that we can use this URL: 

https://content.dropboxapi.com/1/files/auto/<path>

But how do we specify the path? Is it the path starting from the folder name? but what about authentication? How will the URL divert to the correct user and folder?

 

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    For reference, this is a Core API a.k.a. API v1 endpoint, documented here:

    https://www.dropbox.com/developers-v1/core/docs#files_put

    API v1 supports both OAuth 1 and OAuth 2 for authentication, with OAuth 2 being preferred. When you make an API call, the OAuth access token you supply with it identifies the relevant account.

    To specify the path you want to upload to in that account, you put the path on the URL (where the <path> placeholder is shown). This should be the entire path, including any parent folders, as well as the desired filename. E.g., to upload a file as test.txt inside a "Documents" folder in root, the path would be: "/Documents/test.txt".

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Yes, you can use generated access tokens there. OAuth 2 access tokens generated via the App Console work the same as OAuth 2 access tokens retrieved via the OAuth flow (i.e., /oauth2/authorize and /oauth2/token). The only difference is that you can only generate an access token for your own account, whereas the OAuth flow can be used for any account.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    For API v1, you can send these parameters as URL parameters, or form encoded in the body. For example, either of these are valid:

    curl -X "POST" "https://api.dropboxapi.com/1/fileops/copy" \
    -H "Authorization: Bearer <ACCESS_TOKEN>" \
    --data "root=auto&from_path=/test.txt&to_path=/test_new.txt"

    or

    curl -X "POST" "https://api.dropboxapi.com/1/fileops/copy?root=auto&from_path=/test.txt&to_path=/test_new.txt" \
    -H "Authorization: Bearer <ACCESS_TOKEN>"

    (Perhaps you looked at some API v2 documentation at some point? API v2 does take JSON in the body. We generally would recommend using API v2 instead of API v1, if it has all of the functionality you need anyway.)

  • Manmeet Kaur R.'s avatar
    Manmeet Kaur R.
    New member | Level 1

    Thanks, I was trying to use dropbox/foldername or home/foldername and was getting 404. Now it is working fine! 

    One more question or confirmation, this is the path I followed:

    1. Created a new app

    2. used the link to allow access to App and generate the authorization code:

    https://www.dropbox.com/1/oauth2/authorize?client_id=<YOUR-APP-KEY>&response_type=code

    3. then using the below command generated the authorization token for use in the header of the HTTP Request:

    curl https://api.dropbox.com/1/oauth2/token -d grant_type=authorization_code -d code=<YOUR-AUTHORIZATION-CODE> -u <YOUR-APP-KEY>:<YOUR-APP-SECRET>

    My question is  - can we generate the token using the GENERATE button in the OAuth2 section of MyApp and used it as Authorization: Bearer <token> in the header?

    Please advise.

  • Manmeet Kaur R.'s avatar
    Manmeet Kaur R.
    New member | Level 1

    Is there a way to download all the files in the folder? When I just end my URL at the folder name, it gives me 404 error.

    Or is there a way to user regular expressions in the URL?

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    The Dropbox API doesn't offer a way to download an entire folder at once, or files in bulk, so you'll need to iterate through the specific files you want to download. I'll be sure to pass this along as a feature request though.

  • Manmeet Kaur R.'s avatar
    Manmeet Kaur R.
    New member | Level 1

    I am trying to copy a file from one folder to another, but I am getting a 400 error and it does not state what is the error. my payload is like this :

    {
    "root": "auto"
    "from_path": "jobViteTest/file.csv"
    "to_path": "jobViteTest/archive/new_file.csv"
    }

    where both from and to paths are existing but I want to copy and rename the file file.csv to new_file.csv. Can you please advise.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    The body of the response for the API call will contain more information. Please print that out in order to see what the issue is.

  • Manmeet Kaur R.'s avatar
    Manmeet Kaur R.
    New member | Level 1

    I tried to execute this time using POSTMAN as the tool I am using does not print the response. First Postman was not able to complete OAuth 2.0 authorization when I tried to generate the token. Nonetheless, I used the callback api and put it in the settings page and used the generated token. Then it gave me this error:

    {
    "error": "Must send either a from_path or a from_copy_ref"
    }

    I was giving parameters like root, from_path, to_path in the Body as JSON. I even tried to pass these parameters as headers, but still the same error.

About Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,875 PostsLatest Activity: 5 hours ago
323 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!