Unicode C Box: Get Folder Items

Back to Index

Gets all of the files, folders, or web links contained within a folder.

Documentation: https://developer.box.com/reference#get-a-folders-items

CURL Command

curl https://api.box.com/2.0/folders/BOX_FOLDER_ID/items?limit=2&offset=0 \
-H "Authorization: Bearer BOX_ACCESS_TOKEN"

Unicode C Example

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

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jsonResponse;
    int total_count;
    int offset;
    int limit;
    int i;
    int count_i;
    const wchar_t *type;
    const wchar_t *id;
    const wchar_t *file_versionType;
    const wchar_t *file_versionId;
    const wchar_t *file_versionSha1;
    const wchar_t *sequence_id;
    const wchar_t *etag;
    const wchar_t *sha1;
    const wchar_t *name;
    const wchar_t *by;
    const wchar_t *direction;

    rest = CkRestW_Create();

    //  URL: https://api.box.com/2.0/folders/BOX_FOLDER_ID/items?limit=2&offset=0
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"api.box.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;
    }

    CkRestW_AddHeader(rest,L"Authorization",L"Bearer BOX_ACCESS_TOKEN");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/2.0/folders/BOX_FOLDER_ID/items?limit=2&offset=0",sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

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

    total_count = CkJsonObjectW_IntOf(jsonResponse,L"total_count");
    offset = CkJsonObjectW_IntOf(jsonResponse,L"offset");
    limit = CkJsonObjectW_IntOf(jsonResponse,L"limit");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"entries");
    while (i < count_i) {
        CkJsonObjectW_putI(jsonResponse,i);
        type = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].type");
        id = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].id");
        file_versionType = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].file_version.type");
        file_versionId = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].file_version.id");
        file_versionSha1 = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].file_version.sha1");
        sequence_id = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].sequence_id");
        etag = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].etag");
        sha1 = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].sha1");
        name = CkJsonObjectW_stringOf(jsonResponse,L"entries[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"order");
    while (i < count_i) {
        CkJsonObjectW_putI(jsonResponse,i);
        by = CkJsonObjectW_stringOf(jsonResponse,L"order[i].by");
        direction = CkJsonObjectW_stringOf(jsonResponse,L"order[i].direction");
        i = i + 1;
    }



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

    }

Sample JSON Response Body

{
  "total_count": 2,
  "entries": [
    {
      "type": "file",
      "id": "246181882790",
      "file_version": {
        "type": "file_version",
        "id": "259636211878",
        "sha1": "c9d2492fb97f88a9b4d1e35f32a3410e95853f18"
      },
      "sequence_id": "0",
      "etag": "0",
      "sha1": "c9d2492fb97f88a9b4d1e35f32a3410e95853f18",
      "name": "hedgehogs.jpg"
    },
    {
      "type": "file",
      "id": "246167973161",
      "file_version": {
        "type": "file_version",
        "id": "259621592361",
        "sha1": "df7be9dc4f467187783aca68c7ce98e4df2172d0"
      },
      "sequence_id": "0",
      "etag": "0",
      "sha1": "df7be9dc4f467187783aca68c7ce98e4df2172d0",
      "name": "penguins.jpg"
    }
  ],
  "offset": 0,
  "limit": 2,
  "order": [
    {
      "by": "type",
      "direction": "ASC"
    },
    {
      "by": "name",
      "direction": "ASC"
    }
  ]
}