Help

Looking for a way to get file contents from Dropbox API to a script app

Topic Labels: Extensions
1931 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Sergei_RasKar
6 - Interface Innovator
6 - Interface Innovator

Hi!
I’m trying to get file contents from Dropbox, a reverse operation to the one in this topic: Export Rich Text Field as Markdown - kindly described by Bill French, a way to upload csv data from Airtable scripting app to a Dropbox file

I’m using download api method HTTP - Developers - Dropbox

> let dropboxEndpoint1 = "https://content.dropboxapi.com/2/files/download"
> let dropBoxApiArg = { "path": "/" + currFilename }
> let postOptions1 = {
>     method: "POST",
>     headers: {
>         "Authorization" : "Bearer " + appToken,
>         "Dropbox-API-Arg": JSON.stringify(dropBoxApiArg),
>     }
> }
> const postResults1 = await remoteFetchAsync(dropboxEndpoint1, postOptions1);
> const jsonPost1 = await postResults1.json()

I’m getting a reply like this one below (looks like success), but I can’t understand how to get the file contents from this Dropbox response.
“json()” method returns “undefined”.
The file is a simple text file and contents is plain text

{type: "basic", url: "https://content.dropboxapi.com/2/files/download", status: 200, statusText: "OK", ok: true…}
type: "basic"
url: "https://content.dropboxapi.com/2/files/download"
status: 200
statusText: "OK"
ok: true
headers: Object
redirected: false

Appreciate any ideas or recommendations!)

2 Replies 2

Hi @Sergei_RasKar - try this at the end of your script:

let response = await fetch(dropboxEndpoint1, postOptions1);
console.log(await response.text());

It requires text() rather than json()

Thanks a lot for help, Jonathan, it worked like charm.
:pray: