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.

Discuss Dropbox Developer & API

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

Re: Automate DropBox Using Script

Automate DropBox Using Script

jimbob1977
Helpful | Level 6
Go to solution

Hi

I am working on a project that requires sharing of video files to different recipients.

I therefor need to use script to...

- Upload a file from my local folder

- Share the file + get download link

- Email the link to the client

 

I can do parts 1 and 3 - is there any documentation or advice on how to automate the share and link retreival

1 Accepted Solution

Accepted Solutions

Здравко
Legendary | Level 20
Go to solution

Hi @jimbob1977,

If you run Linux, the best place of your question isn't API section. You can get link to arbitrary file in the Dropbox folder using CLI. Take a look on "sharelink" command. :wink:

Unfortunately, CLI is available only on Linux, so if you run something else, this advice isn't for you (or at least, if you don't plane switch to Linux).

Hope this helps to some extent.

View solution in original post

5 Replies 5

Greg-DB
Dropbox Staff
Go to solution

To create a shared link via the Dropbox API, you should use the /2/sharing/create_shared_link_with_settings endpoint:

 

https://www.dropbox.com/developers/documentation/http/documentation#sharing-create_shared_link_with_...

 

That allows you to specify a file or folder and returns a shared link for it. You can then use the link as desired, e.g., to send it to someone. They can then download the linked file or folder from it.

 

Or, to retrieve already existing shared links, you can use /2/sharing/list_shared_links:

 

https://www.dropbox.com/developers/documentation/http/documentation#sharing-list_shared_links

 

By the way, those are links to the documentation for the HTTPS endpoints themselves, but we recommend using one of the official SDKs if possible:

 

https://www.dropbox.com/developers/documentation

 

Those have corresponding native methods for the HTTPS endpoints. 

jimbob1977
Helpful | Level 6
Go to solution

Hi Greg

Thanks for your help.  I've been looking through the API Descriptions and experimented with the API Explorer.

Think I'm missing the p[oint somewhere???

 

To upload a file I am using...

curl -X POST https://content.dropboxapi.com/2/files/upload \
  --header 'Authorization: Bearer MYAUTHCODE' \
  --header 'Content-Type: application/octet-stream' \
  --header 'Dropbox-API-Arg: {"path":"/MyLocalFolder/Clown.jpeg"}' 

When I run this I get the error...

 

{"error_summary": "path/conflict/file/...", "error": {".tag": "path", "reason": {".tag": "conflict", "conflict": {".tag": "file"}}, "upload_session_id": "AAAAAAAAA_Hm7Dp23cYtfg"}

 

The file doesnt exist on my dropbox and is less than 150MB

 

Any ideas as to where I'm going wrong??

jimbob1977
Helpful | Level 6
Go to solution

OK - So I've seen the error of my ways.

To clarify...

The path - is the path withinmy dropbox Apps folder where the file will be located - Correct???

 

Stupid Question - how does it know which file to upload ?? or isd it as simple as it finds a file by same name on local drive?

Greg-DB
Dropbox Staff
Go to solution

The "path" parameter you specify is the path in the Dropbox account where you want to put the uploaded file. If your app uses the "app folder" permission, that path will be used relative to the app folder.

 

The "path/conflict/file" error indicates that there's already something at the specified path, so the upload couldn't complete. Check out the /2/files/upload "mode" parameter documentation for information on configuring what happens in that case.

 

The "path" parameter value is only used to specifying where to upload the file in Dropbox. It is not used to find or specify what data to upload. The data for the file upload is whatever you send in the request body. When using curl on the command line like this, you can specify that data via curl's "--data-binary" option. There's an example of doing so included in the /2/files/upload documentation

 

Здравко
Legendary | Level 20
Go to solution

Hi @jimbob1977,

If you run Linux, the best place of your question isn't API section. You can get link to arbitrary file in the Dropbox folder using CLI. Take a look on "sharelink" command. :wink:

Unfortunately, CLI is available only on Linux, so if you run something else, this advice isn't for you (or at least, if you don't plane switch to Linux).

Hope this helps to some extent.

Need more support?