Delphi DLL Box: Copy Folder

Back to Index

Used to create a copy of a folder in another folder. The original version of the folder will not be altered. The a response status code of 202 is expected for success.

Documentation: https://developer.box.com/reference#copy-a-folder

CURL Command

curl https://api.box.com/2.0/folders/FOLDER_ID/copy \
-H "Authorization: Bearer BOX_ACCESS_TOKEN" \
-d '{"parent": {"id" : DESTINATION_FOLDER_ID}}' \
-X POST

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;
owned_byType: PWideChar;
owned_byId: PWideChar;
owned_byName: PWideChar;
owned_byLogin: PWideChar;
shared_linkUrl: PWideChar;
shared_linkDownload_url: Boolean;
shared_linkVanity_url: Boolean;
shared_linkIs_password_enabled: Boolean;
shared_linkUnshared_at: Boolean;
shared_linkDownload_count: Integer;
shared_linkPreview_count: Integer;
shared_linkAccess: PWideChar;
shared_linkPermissionsCan_download: Boolean;
shared_linkPermissionsCan_preview: Boolean;
folder_upload_emailAccess: PWideChar;
folder_upload_emailEmail: PWideChar;
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;
sha1: PWideChar;

begin
rest := CkRest_Create();

//  URL: https://api.box.com/2.0/folders/FOLDER_ID/copy
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_UpdateNumber(json,'parent.id','DESTINATION_FOLDER_ID');

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

sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestSb(rest,'POST','/2.0/folders/FOLDER_ID/copy',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');
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_linkUrl := CkJsonObject__stringOf(jsonResponse,'shared_link.url');
shared_linkDownload_url := CkJsonObject_IsNullOf(jsonResponse,'shared_link.download_url');
shared_linkVanity_url := CkJsonObject_IsNullOf(jsonResponse,'shared_link.vanity_url');
shared_linkIs_password_enabled := CkJsonObject_BoolOf(jsonResponse,'shared_link.is_password_enabled');
shared_linkUnshared_at := CkJsonObject_IsNullOf(jsonResponse,'shared_link.unshared_at');
shared_linkDownload_count := CkJsonObject_IntOf(jsonResponse,'shared_link.download_count');
shared_linkPreview_count := CkJsonObject_IntOf(jsonResponse,'shared_link.preview_count');
shared_linkAccess := CkJsonObject__stringOf(jsonResponse,'shared_link.access');
shared_linkPermissionsCan_download := CkJsonObject_BoolOf(jsonResponse,'shared_link.permissions.can_download');
shared_linkPermissionsCan_preview := CkJsonObject_BoolOf(jsonResponse,'shared_link.permissions.can_preview');
folder_upload_emailAccess := CkJsonObject__stringOf(jsonResponse,'folder_upload_email.access');
folder_upload_emailEmail := CkJsonObject__stringOf(jsonResponse,'folder_upload_email.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);
    type := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].type');
    id := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].id');
    sequence_id := CkJsonObject__stringOf(jsonResponse,'item_collection.entries[i].sequence_id');
    etag := 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;

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

Sample JSON Response Body

{
  "type": "folder",
  "id": "11446498",
  "sequence_id": "1",
  "etag": "1",
  "name": "Pictures",
  "created_at": "2012-12-12T10:53:43-08:00",
  "modified_at": "2012-12-12T11:15:04-08:00",
  "description": "Some pictures I took",
  "size": 629644,
  "path_collection": {
    "total_count": 1,
    "entries": [
      {
        "type": "folder",
        "id": "0",
        "sequence_id": null,
        "etag": null,
        "name": "All Files"
      }
    ]
  },
  "created_by": {
    "type": "user",
    "id": "17738362",
    "name": "sean rose",
    "login": "sean@box.com"
  },
  "modified_by": {
    "type": "user",
    "id": "17738362",
    "name": "sean rose",
    "login": "sean@box.com"
  },
  "owned_by": {
    "type": "user",
    "id": "17738362",
    "name": "sean rose",
    "login": "sean@box.com"
  },
  "shared_link": {
    "url": "https://www.box.com/s/vspke7y05sb214wjokpk",
    "download_url": null,
    "vanity_url": null,
    "is_password_enabled": false,
    "unshared_at": null,
    "download_count": 0,
    "preview_count": 0,
    "access": "open",
    "permissions": {
      "can_download": true,
      "can_preview": true
    }
  },
  "folder_upload_email": {
    "access": "open",
    "email": "upload.Picture.k13sdz1@u.box.com"
  },
  "parent": {
    "type": "folder",
    "id": "0",
    "sequence_id": null,
    "etag": null,
    "name": "All Files"
  },
  "item_status": "active",
  "item_collection": {
    "total_count": 1,
    "entries": [
      {
        "type": "file",
        "id": "5000948880",
        "sequence_id": "3",
        "etag": "3",
        "sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc",
        "name": "tigers.jpeg"
      }
    ],
    "offset": 0,
    "limit": 100
  }
}