Tcl 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

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://api.box.com/2.0/folders/47885473705
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_UpdateString $json "name" "Old Documents"

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 "PUT" "/2.0/folders/47885473705" $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 trashed_at [CkJsonObject_IsNullOf $jsonResponse "trashed_at"]
set purged_at [CkJsonObject_IsNullOf $jsonResponse "purged_at"]
set content_created_at [CkJsonObject_stringOf $jsonResponse "content_created_at"]
set content_modified_at [CkJsonObject_stringOf $jsonResponse "content_modified_at"]
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_link [CkJsonObject_IsNullOf $jsonResponse "shared_link"]
set folder_upload_email [CkJsonObject_IsNullOf $jsonResponse "folder_upload_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 i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jsonResponse "item_collection.order"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $jsonResponse $i
    set by [CkJsonObject_stringOf $jsonResponse "item_collection.order[i].by"]
    set direction [CkJsonObject_stringOf $jsonResponse "item_collection.order[i].direction"]
    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": "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"
      }
    ]
  }
}