cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

From Where I can get the File ID

From Where I can get the File ID

rajas
New member | Level 2

I am trying to download a file using rest service using V2 API. 

curl -X POST https://api.dropboxapi.com/2/file_requests/get \
    --header "Authorization: Bearer <Access Token>" \
    --header "Content-Type: application/json" \
    --data "{\"id\": \"oaCAVmEyrqYnkZX9955Y\"}"

Where I can get the file id?

 

Thanks in advance.

4 Replies 4

Greg-DB
Dropbox Staff

You can get the ID for a file or folder from the Metadata object for the file or folder, e.g., as returned by /2/files/get_metadata or /2/files/list_folder.

 

If you want to download a file though, you should use /2/files/download (not /2/file_requests/get). For /2/files/download you can supply either the path or ID of the file you want to download. (The /2/file_requests/get endpoint is for getting the information about a file request, not a file, by specifying the ID for the file request.)

rajas
New member | Level 2

Thanks Greg.

bob-locascio
Explorer | Level 3

Greg,

 

The documentation recommends using the File Id, because it is more reliable than the path which changes when the file is moved:

 

  2. File id (e.g. id:odTlUvbpIEFAAAAAAAAGOQ)
      - Unique file reference that persists if files are moved or renamed
      - Useful for apps referencing files that are moved around
      - Best choice for reliable, accurate reference to a specific file

 

But you indicate the only way to get the id is to use the path name.  So programmatically, (I'm writing API calls to manage files/folders from our apps in Salesforce) I need to grab file ids, maybe as each file/folder is created, and store them locally (in Salesforce) so that in the future, I can always find the file?  Not sure how I'd index that store of ids.  I could use file name, if I could guarantee every file name is unique across our enterprise, which I can't.  

 

Seems like I'm stuck with path names, and trying to train users to not mess with the folder structure.  Am I missing something?

Greg-DB
Dropbox Staff

@bob-locascio For reference, while you can get the file ID for a file using its path, that's not the only way to do so. You can get the file ID for a file from any FileMetadata object for the file; FileMetadata objects are used in a number of places on the Dropbox API. For example, you can use /2/files/list_folder[/continue] to list the contents of a folder, such as by supplying the folder's path or ID, or empty string "" for root, and get the file IDs for files in that folder from the returned FileMetadata objects. (If you're interested, you can see all of the places where FileMetadata is used in the API specification.)

 

Anyway, I don't know exactly what constraints and requirements you have in your own environment, but in Dropbox itself, note that in an account multiple files can have the same file name (that is, different files in different folders can have the same name), but multiple files can't have the same file path (that is, different files in the same folder can't have the same name). Dropbox file IDs are unique across all of Dropbox.

 

Exactly how you store any such metadata on your side is up to you, depending on what you need your app to do and how, so I can't really offer specific guidance on how you should structure that.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    bob-locascio Explorer | Level 3
  • User avatar
    rajas New member | Level 2
What do Dropbox user levels mean?