Tcl 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

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://api.box.com/2.0/folders/FOLDER_ID/copy
set bTls 1
set port 443
set bAutoReconnect 1
set success [CkRest_Connect $rest "api.box.com" $port $bTls $bAutoReconnect]
if {[expr $success != 1]} then {
    puts "ConnectFailReason: [CkRest_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

set json [new_CkJsonObject]

CkJsonObject_UpdateNumber $json "parent.id" "DESTINATION_FOLDER_ID"

CkRest_AddHeader $rest "Authorization" "Bearer BOX_ACCESS_TOKEN"

set sbRequestBody [new_CkStringBuilder]

CkJsonObject_EmitSb $json $sbRequestBody
set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestSb $rest "POST" "/2.0/folders/FOLDER_ID/copy" $sbRequestBody $sbResponseBody]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jsonResponse [new_CkJsonObject]

CkJsonObject_LoadSb $jsonResponse $sbResponseBody

set type [CkJsonObject_stringOf $jsonResponse "type"]
set id [CkJsonObject_stringOf $jsonResponse "id"]
set sequence_id [CkJsonObject_stringOf $jsonResponse "sequence_id"]
set etag [CkJsonObject_stringOf $jsonResponse "etag"]
set name [CkJsonObject_stringOf $jsonResponse "name"]
set created_at [CkJsonObject_stringOf $jsonResponse "created_at"]
set modified_at [CkJsonObject_stringOf $jsonResponse "modified_at"]
set description [CkJsonObject_stringOf $jsonResponse "description"]
set size [CkJsonObject_IntOf $jsonResponse "size"]
set path_collectionTotal_count [CkJsonObject_IntOf $jsonResponse "path_collection.total_count"]
set created_byType [CkJsonObject_stringOf $jsonResponse "created_by.type"]
set created_byId [CkJsonObject_stringOf $jsonResponse "created_by.id"]
set created_byName [CkJsonObject_stringOf $jsonResponse "created_by.name"]
set created_byLogin [CkJsonObject_stringOf $jsonResponse "created_by.login"]
set modified_byType [CkJsonObject_stringOf $jsonResponse "modified_by.type"]
set modified_byId [CkJsonObject_stringOf $jsonResponse "modified_by.id"]
set modified_byName [CkJsonObject_stringOf $jsonResponse "modified_by.name"]
set modified_byLogin [CkJsonObject_stringOf $jsonResponse "modified_by.login"]
set owned_byType [CkJsonObject_stringOf $jsonResponse "owned_by.type"]
set owned_byId [CkJsonObject_stringOf $jsonResponse "owned_by.id"]
set owned_byName [CkJsonObject_stringOf $jsonResponse "owned_by.name"]
set owned_byLogin [CkJsonObject_stringOf $jsonResponse "owned_by.login"]
set shared_linkUrl [CkJsonObject_stringOf $jsonResponse "shared_link.url"]
set shared_linkDownload_url [CkJsonObject_IsNullOf $jsonResponse "shared_link.download_url"]
set shared_linkVanity_url [CkJsonObject_IsNullOf $jsonResponse "shared_link.vanity_url"]
set shared_linkIs_password_enabled [CkJsonObject_BoolOf $jsonResponse "shared_link.is_password_enabled"]
set shared_linkUnshared_at [CkJsonObject_IsNullOf $jsonResponse "shared_link.unshared_at"]
set shared_linkDownload_count [CkJsonObject_IntOf $jsonResponse "shared_link.download_count"]
set shared_linkPreview_count [CkJsonObject_IntOf $jsonResponse "shared_link.preview_count"]
set shared_linkAccess [CkJsonObject_stringOf $jsonResponse "shared_link.access"]
set shared_linkPermissionsCan_download [CkJsonObject_BoolOf $jsonResponse "shared_link.permissions.can_download"]
set shared_linkPermissionsCan_preview [CkJsonObject_BoolOf $jsonResponse "shared_link.permissions.can_preview"]
set folder_upload_emailAccess [CkJsonObject_stringOf $jsonResponse "folder_upload_email.access"]
set folder_upload_emailEmail [CkJsonObject_stringOf $jsonResponse "folder_upload_email.email"]
set parentType [CkJsonObject_stringOf $jsonResponse "parent.type"]
set parentId [CkJsonObject_stringOf $jsonResponse "parent.id"]
set parentSequence_id [CkJsonObject_IsNullOf $jsonResponse "parent.sequence_id"]
set parentEtag [CkJsonObject_IsNullOf $jsonResponse "parent.etag"]
set parentName [CkJsonObject_stringOf $jsonResponse "parent.name"]
set item_status [CkJsonObject_stringOf $jsonResponse "item_status"]
set item_collectionTotal_count [CkJsonObject_IntOf $jsonResponse "item_collection.total_count"]
set item_collectionOffset [CkJsonObject_IntOf $jsonResponse "item_collection.offset"]
set item_collectionLimit [CkJsonObject_IntOf $jsonResponse "item_collection.limit"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "path_collection.entries"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $jsonResponse $i
    set type [CkJsonObject_stringOf $jsonResponse "path_collection.entries[i].type"]
    set id [CkJsonObject_stringOf $jsonResponse "path_collection.entries[i].id"]
    set sequence_id_bool [CkJsonObject_IsNullOf $jsonResponse "path_collection.entries[i].sequence_id"]
    set etag_bool [CkJsonObject_IsNullOf $jsonResponse "path_collection.entries[i].etag"]
    set name [CkJsonObject_stringOf $jsonResponse "path_collection.entries[i].name"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "item_collection.entries"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $jsonResponse $i
    set type [CkJsonObject_stringOf $jsonResponse "item_collection.entries[i].type"]
    set id [CkJsonObject_stringOf $jsonResponse "item_collection.entries[i].id"]
    set sequence_id [CkJsonObject_stringOf $jsonResponse "item_collection.entries[i].sequence_id"]
    set etag [CkJsonObject_stringOf $jsonResponse "item_collection.entries[i].etag"]
    set sha1 [CkJsonObject_stringOf $jsonResponse "item_collection.entries[i].sha1"]
    set name [CkJsonObject_stringOf $jsonResponse "item_collection.entries[i].name"]
    set i [expr $i + 1]
}

delete_CkRest $rest
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $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
  }
}