Unicode C Dropbox: Dropbox List Contents of Folder

Back to Index

Starts returning the contents of a folder. If the result's ListFolderResult.has_more field is true, call list_folder/continue with the returned ListFolderResult.cursor to retrieve more entries.

Documentation: https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder

CURL Command

curl -X POST https://api.dropboxapi.com/2/files/list_folder \
    --header "Authorization: Bearer DROPBOX-ACCESS-TOKEN" \
    --header "Content-Type: application/json" \
    --data "{\"path\": \"/Homework/math\",\"recursive\": false,\"include_media_info\": false,\"include_deleted\": false,\"include_has_explicit_shared_members\": false,\"include_mounted_folders\": true}"

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;
    HCkJsonObjectW jsonResponse;
    int i;
    int count_i;
    const wchar_t *cursor;
    BOOL has_more;
    const wchar_t *Tag;
    const wchar_t *name;
    const wchar_t *path_lower;
    const wchar_t *path_display;
    const wchar_t *id;
    const wchar_t *client_modified;
    const wchar_t *server_modified;
    const wchar_t *rev;
    int size;
    const wchar_t *content_hash;

    rest = CkRestW_Create();

    //  URL: https://api.dropboxapi.com/2/files/list_folder
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"api.dropboxapi.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    //  See the Online Tool for Generating JSON Creation Code
    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"path",L"/Homework/math");
    CkJsonObjectW_UpdateBool(json,L"recursive",FALSE);
    CkJsonObjectW_UpdateBool(json,L"include_media_info",FALSE);
    CkJsonObjectW_UpdateBool(json,L"include_deleted",FALSE);
    CkJsonObjectW_UpdateBool(json,L"include_has_explicit_shared_members",FALSE);
    CkJsonObjectW_UpdateBool(json,L"include_mounted_folders",TRUE);

    CkRestW_AddHeader(rest,L"Authorization",L"Bearer DROPBOX-ACCESS-TOKEN");
    CkRestW_AddHeader(rest,L"Content-Type",L"application/json");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"POST",L"/2/files/list_folder",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRestW_getResponseStatusCode(rest);
    if (respStatusCode >= 400) {
        wprintf(L"Response Status Code = %d\n",respStatusCode);
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkRestW_responseHeader(rest));
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
        CkRestW_Dispose(rest);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jsonResponse,sbResponseBody);

    //  See the Online Tool for Generating JSON Parse Code

    cursor = CkJsonObjectW_stringOf(jsonResponse,L"cursor");
    has_more = CkJsonObjectW_BoolOf(jsonResponse,L"has_more");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"entries");
    while (i < count_i) {
        CkJsonObjectW_putI(jsonResponse,i);
        Tag = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].\".tag\"");
        name = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].name");
        path_lower = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].path_lower");
        path_display = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].path_display");
        id = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].id");
        client_modified = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].client_modified");
        server_modified = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].server_modified");
        rev = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].rev");
        size = CkJsonObjectW_IntOf(jsonResponse,L"entries[i].size");
        content_hash = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].content_hash");
        i = i + 1;
    }



    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "entries": [
    {
      ".tag": "file",
      "name": "Matrices.txt",
      "path_lower": "/homework/math/matrices.txt",
      "path_display": "/Homework/math/Matrices.txt",
      "id": "id:qk7WwvROeSAAAAAAAAAAAQ",
      "client_modified": "2016-06-02T20:41:02Z",
      "server_modified": "2016-06-02T20:41:03Z",
      "rev": "5482db15f",
      "size": 6,
      "content_hash": "5a3c776e2631edabe2ba710ac72301b3aeca821ba4f7d36b56cc6050ea6c2ba8"
    },
    {
      ".tag": "file",
      "name": "Document.docx",
      "path_lower": "/homework/math/document.docx",
      "path_display": "/Homework/math/Document.docx",
      "id": "id:JSXYsxHo1hAAAAAAAAAABw",
      "client_modified": "2018-10-22T21:59:23Z",
      "server_modified": "2018-10-22T21:59:23Z",
      "rev": "10482db15f",
      "size": 11009,
      "content_hash": "ab9c1887a653a8f42e4401425ac02839e1f76533e1d44ac8d0605d870a16c25d"
    }
  ],
  "cursor": "AAHnmmjY1IztwebFmkByuZ_Vgzz-tSYXYE3KhdkUxBfETpGjPqTBz7ZzBj1G7zkPPVanKCt0FtzqXjDQ2ggQKYZTiL4mJ346fRelmP049QjN5CZzeMHbD_lSFqA96Br36vR9YLg40VAHu42TcCG38MbUPOCKa-wdguu5C1JsgYvIaXIcjRMCfbxz98JdYhhefmu0pjoxtgtCstOrmp_pXIng",
  "has_more": false
}