Delphi DLL Box: Update Folder

Back to Index

Renames a folder. This example renames the folder w/ id = 47885473705 to "Old Documents".

Documentation: https://developer.box.com/reference#update-information-about-a-folder

CURL Command

curl https://api.box.com/2.0/folders/47885473705 \
-H "Authorization: Bearer BOX_ACCESS_TOKEN" \
-d '{"name":"Old Documents"}' \
-X PUT

Delphi DLL Example

var
rest: HCkRest;
success: Boolean;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
json: HCkJsonObject;
sbRequestBody: HCkStringBuilder;
sbResponseBody: HCkStringBuilder;
jsonResponse: HCkJsonObject;
type: PWideChar;
id: PWideChar;
sequence_id: PWideChar;
etag: PWideChar;
name: PWideChar;
created_at: PWideChar;
modified_at: PWideChar;
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: PWideChar;
content_modified_at: PWideChar;
owned_byType: PWideChar;
owned_byId: PWideChar;
owned_byName: PWideChar;
owned_byLogin: PWideChar;
shared_link: Boolean;
folder_upload_email: Boolean;
parentType: PWideChar;
parentId: PWideChar;
parentSequence_id: Boolean;
parentEtag: Boolean;
parentName: PWideChar;
item_status: PWideChar;
item_collectionTotal_count: Integer;
item_collectionOffset: Integer;
item_collectionLimit: Integer;
i: Integer;
count_i: Integer;
sequence_id_bool: Boolean;
etag_bool: Boolean;
by: PWideChar;
direction: PWideChar;

begin
rest := CkRest_Create();

//  URL: https://api.box.com/2.0/folders/47885473705
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;

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'name','Old Documents');

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

sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestSb(rest,'PUT','/2.0/folders/47885473705',sbRequestBody,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__stringOf(jsonResponse,'sequence_id');
etag := CkJsonObject__stringOf(jsonResponse,'etag');
name := CkJsonObject__stringOf(jsonResponse,'name');
created_at := CkJsonObject__stringOf(jsonResponse,'created_at');
modified_at := CkJsonObject__stringOf(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__stringOf(jsonResponse,'content_created_at');
content_modified_at := CkJsonObject__stringOf(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');
parentType := CkJsonObject__stringOf(jsonResponse,'parent.type');
parentId := CkJsonObject__stringOf(jsonResponse,'parent.id');
parentSequence_id := CkJsonObject_IsNullOf(jsonResponse,'parent.sequence_id');
parentEtag := CkJsonObject_IsNullOf(jsonResponse,'parent.etag');
parentName := CkJsonObject__stringOf(jsonResponse,'parent.name');
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);
    type := CkJsonObject__stringOf(jsonResponse,'path_collection.entries[i].type');
    id := CkJsonObject__stringOf(jsonResponse,'path_collection.entries[i].id');
    sequence_id_bool := CkJsonObject_IsNullOf(jsonResponse,'path_collection.entries[i].sequence_id');
    etag_bool := CkJsonObject_IsNullOf(jsonResponse,'path_collection.entries[i].etag');
    name := CkJsonObject__stringOf(jsonResponse,'path_collection.entries[i].name');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jsonResponse,'item_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.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);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jsonResponse);

Sample JSON Response Body

{
  "type": "folder",
  "id": "47885473705",
  "sequence_id": "1",
  "etag": "1",
  "name": "Old Documents",
  "created_at": "2018-03-16T06:54:57-07:00",
  "modified_at": "2018-03-17T08:36:09-07:00",
  "description": "",
  "size": 0,
  "path_collection": {
    "total_count": 1,
    "entries": [
      {
        "type": "folder",
        "id": "0",
        "sequence_id": null,
        "etag": null,
        "name": "All Files"
      }
    ]
  },
  "created_by": {
    "type": "user",
    "id": "2787704945",
    "name": "chilkat",
    "login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
  },
  "modified_by": {
    "type": "user",
    "id": "2787704945",
    "name": "chilkat",
    "login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
  },
  "trashed_at": null,
  "purged_at": null,
  "content_created_at": "2018-03-16T06:54:57-07:00",
  "content_modified_at": "2018-03-17T08:36:09-07:00",
  "owned_by": {
    "type": "user",
    "id": "2787704945",
    "name": "chilkat",
    "login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
  },
  "shared_link": null,
  "folder_upload_email": null,
  "parent": {
    "type": "folder",
    "id": "0",
    "sequence_id": null,
    "etag": null,
    "name": "All Files"
  },
  "item_status": "active",
  "item_collection": {
    "total_count": 0,
    "entries": [
    ],
    "offset": 0,
    "limit": 100,
    "order": [
      {
        "by": "type",
        "direction": "ASC"
      },
      {
        "by": "name",
        "direction": "ASC"
      }
    ]
  }
}