I can't figure out how I can call Dropbox API usin...
# ktor
s
I can't figure out how I can call Dropbox API using Ktor 1. I need to post JSON data to this endpoint: https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder This does not work:
Copy code
var delta: DropboxDelta = post("$DROPBOX_API_URL/files/list_folder") {
    contentType(ContentType.Application.Json)
    body = Parameters.build {
        append("path", "/")
        append("recursive", "true")
        append("include_non_downloadable_files", "false")
    }.formUrlEncode()
}
Client request(https://api.dropboxapi.com/2/files/list_folder) invalid: 400 Bad Request. Text: "Error in call to API function "files/list_folder": request body: expected object, got string" For OAuth I can use this construct:
Copy code
return tokenClient.submitForm(
    url = tokenUrl,
    formParameters = Parameters.build {
        append("grant_type", "authorization_code")
        append("code", authorizationCode)
        append("client_id", clientId)
    }
)
But that does not work with list_folder Can someone share an example how to do this?
2
Ok, I figured it out. For Dropbox you need to have this:
Copy code
var delta: DropboxDelta = post("$DROPBOX_API_URL/files/list_folder") {
    contentType(ContentType.Application.Json)
    body = DropboxDeltaRequest()
}
Copy code
@Serializable
data class DropboxDeltaRequest(

    @Required
    val path: String = "",

    @Required
    val recursive: Boolean = true,

    @Required
    @SerialName("include_non_downloadable_files")
    val includeNonDownloadableFiles: Boolean = false

)
I hope that saves someone else time. Ktor doc really has a lot of potential for improvement.
👍 1