Page 1 of 2

Generate Dropbox link

Posted: Wed Feb 01, 2023 6:01 am
by ring4life70
Hi,
I have several files in a dropbox shared folder.
I am trying to figure out if with ffatrans,is possible to create a workflow that copies the dropbox link of a file and send it off via email.
please can you help me or suggest a work around to do this ?

Re: Copy Dropbox link

Posted: Wed Feb 01, 2023 8:39 am
by emcodem
Hey,

absolutely, we just need to utilize the vendors corresponding API for that. As most modern systems they use "oauth2", which means you first have to create an "access token" manually. From experience most vendors let you pay extra for this kind of functionality, so before i go on and create some example workflow (using http processor) for you, i need you to confirm that you are able to create such an api token.
Honestly i'm totally interested in this because i have far too less experience with this oauth stuff so i'd be happy if the 2 of us bring this topic to the end.

So, as far as i understand what you need to do is in your account, you create an "app in the app console", and generate an access token see point 3:
https://developers.dropbox.com/oauth-guide

This access token will be something we re-use for any api call to dropbox.

Once you have the API token, what we need to do is this:
https://www.dropbox.com/developers/docu ... h_settings

Let me know if you can get such a token and we can proceed.

Re: Copy Dropbox link

Posted: Wed Feb 01, 2023 9:01 am
by emcodem
ok, actually i couldnt resist and tested with a free account. It's pretty straight forward overall.
The only thing that was tricky was that when creating the app in my account, before i hit the "generate access token" button, on the permissions tab, i needed to set the sharing.write and apply the new setting. Otherwise i always got a response "missing scope". After that, hit generate access token and save it for later use in your workflow (do not share the access token with anyone, ever)

The following is just for later reference in case you were able to generate your token and ready to proceed, i save this information here so the information does not get lost.

Set http processor to POST to:
URL: https://api.dropboxapi.com/2/sharing/cr ... h_settings
Header: Authorization: Bearer ___APP_TOKEN___
Body: {"path":"/out.h264","settings":{"access":"viewer","allow_download":true,"audience":"public","requested_visibility":"public"}}

This creates a link to out.h264 which is in the root folder of my dropbox. The response needs then to be saved in a variable and we need to $jsonget("%s_response%","url") to retrieve the created link.

Re: Generate Dropbox link

Posted: Wed Feb 01, 2023 8:55 pm
by ring4life70
thanks emcodem,
tomorrow morning I will check if with my account is possible to generate the this Token without extra cost and I will update you.
thanks again

Re: Generate Dropbox link

Posted: Thu Feb 02, 2023 8:17 am
by ring4life70
hi emcodem,
i can confirm you, that i have my personal account token, and we can proceed

Re: Generate Dropbox link

Posted: Thu Feb 02, 2023 11:27 am
by emcodem
OK perfect.
Here is the workflow:
emcodem_drobox_create_link.json
(17.59 KiB) Downloaded 182 times
Note that i left all my personal data in the first processor of the workflow as example values because i have dropbox only for testing and i don't care if anyone tries creating random download links on my dropbox :D

The stuff was relatively hard to understand and has some limitations. I learned that what we did before ("generate access token") is not really helpful but for testing for short time only. But i believe i found out how it can work fully automated. Here is how it goes:

Let us start with what you need to do manually before you can use the workflow.
  • 1) In First processor of the workflow "Dropbox Preparation", insert your appkey and appsecret. They are easy to retrieve at the same spot where you actually created the app in your dropbox account and set the permission before.
  • 2) Manually open the url in a browser (replace __APPKEY__ by your appkey)

    Code: Select all

    https://www.dropbox.com/oauth2/authorize?client_id=___APPKEY___&token_access_type=offline&response_type=code
  • 3) Insert the manually retrieved access code into the first processor of the workflow.
  • 4) Now you must be quick, the access code is only valid for some minutes. You must successfully execute the workflow ONCE now before it can be used later fully automated.
What is access_code and refresh_token:
access_code: must be retrieved manually, is valid only for 1 hour or so.
refresh_token: is automatically retrieved ONCE using the access_code (the big error path of the workflow). It is used for fully automated link generation later on

The manually retrieved access_code is used to retrieve the so called refresh_token. The refresh token can be re-used for long time (they dont specify what that means, hopefully years). So retrieving the refresh_token could also be done "manually" completely but as it is a http post call which are not so easy to execute manually, i added that functionality to the workflow, even if it is executed only ONCE. The token is automatically saved by the workflow at first run to c:\temp\refreshtoken.txt. If you loose that file, you must get a new access_token.

First time using the workflow:
  • 1.a) After you inserted appkey and secret (and local dropbox root) as well as the new and shiny access code into the first processor of the workflow, you immediately manually submit one file that resides in the root folder of your dropbox to the first processor.
  • 2.a) The workflow should recognize the authorisation error and go the big error path in order to use the access_code for retrieving and saving the refresh_token. It will save to C:\temp\refreshtoken.txt and be used from this moment on.
  • 3.a) Make sure you set local dropbox root in the first processor and submit a file from there which is already uploaded on dropbox.com
  • 4.a) As a final result you should see the created download link in the workflow status.
Problems:
  • 1.b) you cannot create multiple links to the same file, once one link was created and you resubmit the same file again, it will error and say "link
    already exists". Potential workaround is to store generated links in a local file (e.g. json) and re-retrieve the link from there if needed.
  • 2.b) The "dropbox_root" you enter at first populate processor is used for calculating the relative filename on dropbox. You can only submit files from within this folder, otherwise the path calculation will fail. E.g. if c:\dropbox is your upload folder and therefore your dropbox_root, exactly this will be subtracted from the submitted local filepath, e.g. you submit c:\dropbox\folder\file.txt, then c:\dropbox is subtracted, ending up in the dropbox path /folder/file.txt - this file has to be uplaoded already before you start the workflow
  • 3.b) later on we want to automate the process using watchfolder. This is kind of problematic because we don't know when the file has been uploaded to dropbox. For start we can just use a sleep processor and sleep as long as we think it takes maximum from file drop to upload complete. We can potentially use plugin processor http comm+ to actually wait until the file exists on dropbox but thats a different story.
Re-authorize:
  • 1.c) if for whatever reason the authorisation stops working after it worked once, repeat step 2) (get a new appkey that allows getting a new refresh_token) - note that i don't expect this to happen very frequently. But it is problematic as it requires manual interaction
  • 2.c) i have no clue if we must reset everything in case e.g. we change app permissions on dropbox. To reset, just delete c:\temp\refreshtoken.txt and repeat step 2)
Thanks to: i used this for getting started with the appkey stuff: https://www.codemzy.com/blog/dropbox-lo ... resh-token

Re: Generate Dropbox link

Posted: Tue Feb 07, 2023 5:42 pm
by ring4life70
Hi,emcodem,
Apologies for the late reply, but I was able to do some tests only today, as you can see in the screenshot the workflow returns me an error on the HTTP comunication:
Capture1.png
Capture1.png (97.19 KiB) Viewed 3004 times

and here below the error message, in my dropbox app console, sharing.write option is already enabled

3Capture.png
3Capture.png (128.78 KiB) Viewed 3004 times

Re: Generate Dropbox link

Posted: Tue Feb 07, 2023 7:27 pm
by emcodem
Hi,

so i got that error too, mentioned that in my second post here. E.g. it only worked for me when i first gave the permissions and then did all the generate token stuff. So i suspect after you set this sharing.write permission, you have to restart procedure at 2)

Re: Generate Dropbox link

Posted: Wed Feb 08, 2023 6:27 am
by ring4life70
thanks emcodem,
i restarted the procedure from step 2, but now the error has changed . HTTP status: Conflict, msg: "{"error_summary": "path/malformed_path/.", "error": {".tag": "path", "path": {".tag": "malformed_path"}}", code: 409

Re: Generate Dropbox link

Posted: Wed Feb 08, 2023 7:17 am
by emcodem
Cool, that means that all the preparation stuff worked now and we just have to care about the path calculation.
Please check 2.b and if no success, please upload the full_log.json of a failed job.
Also, when creating the app/permissions, you had an option to "limit to a folder" or give full dropbox permission, did you limit to a folder there?