Delphi DLL Box: Get Root Folder Info

Back to Index

Gets the folder info for the root folder of a Box.com account. The root folder of a box.com account always has an id = "0".

Documentation: https://developer.box.com/reference#get-folder-info

CURL Command

curl https://api.box.com/2.0/folders/0 \
-H "Authorization: Bearer BOX_ACCESS_TOKEN" \

Delphi DLL Example

var
rest: HCkRest;
success: Boolean;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
sbResponseBody: HCkStringBuilder;
jsonResponse: HCkJsonObject;
type: PWideChar;
id: PWideChar;
sequence_id: Boolean;
etag: Boolean;
name: PWideChar;
created_at: Boolean;
modified_at: Boolean;
description: PWideChar;
size: Integer;
path_collectionTotal_count: Integer;
created_byType: PWideChar;
created_byId: PWideChar;
created_byName: PWideChar;
created_byLogin: PWideChar;
modified_byType: PWideChar;
modified_byId: PWideChar;
modified_byName: PWideChar;
modified_byLogin: PWideChar;
trashed_at: Boolean;
purged_at: Boolean;
content_created_at: Boolean;
content_modified_at: Boolean;
owned_byType: PWideChar;
owned_byId: PWideChar;
owned_byName: PWideChar;
owned_byLogin: PWideChar;
shared_link: Boolean;
folder_upload_email: Boolean;
parent: Boolean;
item_status: PWideChar;
item_collectionTotal_count: Integer;
item_collectionOffset: Integer;
item_collectionLimit: Integer;
i: Integer;
count_i: Integer;
file_versionType: PWideChar;
file_versionId: PWideChar;
file_versionSha1: PWideChar;
sequence_id_str: PWideChar;
etag_str: PWideChar;
sha1: PWideChar;
by: PWideChar;
direction: PWideChar;

begin
rest := CkRest_Create();

//  URL: https://api.box.com/2.0/folders/0
bTls := True;
port := 443;
bAutoReconnect := True;
success := CkRest_Connect(rest,'api.box.com',port,bTls,bAutoReconnect);
if (success <> True) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

CkRest_AddHeader(rest,'Authorization','Bearer BOX_ACCESS_TOKEN');

sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestNoBodySb(rest,'GET','/2.0/folders/0',sbResponseBody);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

jsonResponse := CkJsonObject_Create();
CkJsonObject_LoadSb(jsonResponse,sbResponseBody);

type := CkJsonObject__stringOf(jsonResponse,'type');
id := CkJsonObject__stringOf(jsonResponse,'id');
sequence_id := CkJsonObject_IsNullOf(jsonResponse,'sequence_id');
etag := CkJsonObject_IsNullOf(jsonResponse,'etag');
name := CkJsonObject__stringOf(jsonResponse,'name');
created_at := CkJsonObject_IsNullOf(jsonResponse,'created_at');
modified_at := CkJsonObject_IsNullOf(jsonResponse,'modified_at');
description := CkJsonObject__stringOf(jsonResponse,'description');
size := CkJsonObject_IntOf(jsonResponse,'size');
path_collectionTotal_count := CkJsonObject_IntOf(jsonResponse,'path_collection.total_count');
created_byType := CkJsonObject__stringOf(jsonResponse,'created_by.type');
created_byId := CkJsonObject__stringOf(jsonResponse,'created_by.id');
created_byName := CkJsonObject__stringOf(jsonResponse,'created_by.name');
created_byLogin := CkJsonObject__stringOf(jsonResponse,'created_by.login');
modified_byType := CkJsonObject__stringOf(jsonResponse,'modified_by.type');
modified_byId := CkJsonObject__stringOf(jsonResponse,'modified_by.id');
modified_byName := CkJsonObject__stringOf(jsonResponse,'modified_by.name');
modified_byLogin := CkJsonObject__stringOf(jsonResponse,'modified_by.login');
trashed_at := CkJsonObject_IsNullOf(jsonResponse,'trashed_at');
purged_at := CkJsonObject_IsNullOf(jsonResponse,'purged_at');
content_created_at := CkJsonObject_IsNullOf(jsonResponse,'content_created_at');
content_modified_at := CkJsonObject_IsNullOf(jsonResponse,'content_modified_at');
owned_byType := CkJsonObject__stringOf(jsonResponse,'owned_by.type');
owned_byId := CkJsonObject__stringOf(jsonResponse,'owned_by.id');
owned_byName := CkJsonObject__stringOf(jsonResponse,'owned_by.name');
owned_byLogin := CkJsonObject__stringOf(jsonResponse,'owned_by.login');
shared_link := CkJsonObject_IsNullOf(jsonResponse,'shared_link');
folder_upload_email := CkJsonObject_IsNullOf(jsonResponse,'folder_upload_email');
parent := CkJsonObject_IsNullOf(jsonResponse,'parent');
item_status := CkJsonObject__stringOf(jsonResponse,'item_status');
item_collectionTotal_count := CkJsonObject_IntOf(jsonResponse,'item_collection.total_count');
item_collectionOffset := CkJsonObject_IntOf(jsonResponse,'item_collection.offset');
item_collectionLimit := CkJsonObject_IntOf(jsonResponse,'item_collection.limit');
i := 0;
count_i := CkJsonObject_SizeOfArray(jsonResponse,'path_collection.entries');
while i < count_i do
  begin
CkJsonObject_putI(jsonResponse,i);
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jsonResponse,'item_collection.entries');
while i < count_i do
  begin
CkJsonObject_putI(jsonResponse,i);
    type := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].type');
    id := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].id');
    file_versionType := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].file_version.type');
    file_versionId := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].file_version.id');
    file_versionSha1 := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].file_version.sha1');
    sequence_id_str := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].sequence_id');
    etag_str := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].etag');
    sha1 := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].sha1');
    name := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].name');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jsonResponse,'item_collection.order');
while i < count_i do
  begin
CkJsonObject_putI(jsonResponse,i);
    by := CkJsonObject__stringOf(jsonResponse,'item_collection.order[i].by');
    direction := CkJsonObject__stringOf(jsonResponse,'item_collection.order[i].direction');
    i := i + 1;
  end;

CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jsonResponse);

Sample JSON Response Body

{
  "type": "folder",
  "id": "0",
  "sequence_id": null,
  "etag": null,
  "name": "All Files",
  "created_at": null,
  "modified_at": null,
  "description": "",
  "size": 826408,
  "path_collection": {
    "total_count": 0,
    "entries": [
    ]
  },
  "created_by": {
    "type": "user",
    "id": "",
    "name": "",
    "login": ""
  },
  "modified_by": {
    "type": "user",
    "id": "2787704945",
    "name": "chilkat",
    "login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
  },
  "trashed_at": null,
  "purged_at": null,
  "content_created_at": null,
  "content_modified_at": null,
  "owned_by": {
    "type": "user",
    "id": "2787704945",
    "name": "chilkat",
    "login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
  },
  "shared_link": null,
  "folder_upload_email": null,
  "parent": null,
  "item_status": "active",
  "item_collection": {
    "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": 100,
    "order": [
      {
        "by": "type",
        "direction": "ASC"
      },
      {
        "by": "name",
        "direction": "ASC"
      }
    ]
  }
}