DataFlex 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

DataFlex Example

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Boolean iBTls
    Integer iPort
    Boolean iBAutoReconnect
    Handle hoJson
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vSbResponseBody
    Handle hoSbResponseBody
Response    Handle hoJsonResponse
    String sType
    String sId
    String sSequence_id
    String sEtag
    String sName
    String sCreated_at
    String sModified_at
    String sDescription
    Integer iSize
    Integer iPath_collectionTotal_count
    String sCreated_byType
    String sCreated_byId
    String sCreated_byName
    String sCreated_byLogin
    String sModified_byType
    String sModified_byId
    String sModified_byName
    String sModified_byLogin
    Boolean iTrashed_at
    Boolean iPurged_at
    String sContent_created_at
    String sContent_modified_at
    String sOwned_byType
    String sOwned_byId
    String sOwned_byName
    String sOwned_byLogin
    Boolean iShared_link
    Boolean iFolder_upload_email
    String sParentType
    String sParentId
    Boolean iParentSequence_id
    Boolean iParentEtag
    String sParentName
    String sItem_status
    Integer iItem_collectionTotal_count
    Integer iItem_collectionOffset
    Integer iItem_collectionLimit
    Integer i
    Integer iCount_i
    Boolean iSequence_id_bool
    Boolean iEtag_bool
    String sBy
    String sDirection
    String sTemp1
    Integer iTemp1

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    //  URL: https://api.box.com/2.0/folders/47885473705
    Move True To iBTls
    Move 443 To iPort
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "api.box.com" iPort iBTls iBAutoReconnect To iSuccess
    If (iSuccess <> True) Begin
        Get ComConnectFailReason Of hoRest To iTemp1
        Showln "ConnectFailReason: " iTemp1
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "name" "Old Documents" To iSuccess

    Get ComAddHeader Of hoRest "Authorization" "Bearer BOX_ACCESS_TOKEN" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComEmitSb Of hoJson vSbRequestBody To iSuccess
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestSb Of hoRest "PUT" "/2.0/folders/47885473705" vSbRequestBody vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
    If (Not(IsComObjectCreated(hoJsonResponse))) Begin
        Send CreateComObject of hoJsonResponse
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess

    Get ComStringOf Of hoJsonResponse "type" To sType
    Get ComStringOf Of hoJsonResponse "id" To sId
    Get ComStringOf Of hoJsonResponse "sequence_id" To sSequence_id
    Get ComStringOf Of hoJsonResponse "etag" To sEtag
    Get ComStringOf Of hoJsonResponse "name" To sName
    Get ComStringOf Of hoJsonResponse "created_at" To sCreated_at
    Get ComStringOf Of hoJsonResponse "modified_at" To sModified_at
    Get ComStringOf Of hoJsonResponse "description" To sDescription
    Get ComIntOf Of hoJsonResponse "size" To iSize
    Get ComIntOf Of hoJsonResponse "path_collection.total_count" To iPath_collectionTotal_count
    Get ComStringOf Of hoJsonResponse "created_by.type" To sCreated_byType
    Get ComStringOf Of hoJsonResponse "created_by.id" To sCreated_byId
    Get ComStringOf Of hoJsonResponse "created_by.name" To sCreated_byName
    Get ComStringOf Of hoJsonResponse "created_by.login" To sCreated_byLogin
    Get ComStringOf Of hoJsonResponse "modified_by.type" To sModified_byType
    Get ComStringOf Of hoJsonResponse "modified_by.id" To sModified_byId
    Get ComStringOf Of hoJsonResponse "modified_by.name" To sModified_byName
    Get ComStringOf Of hoJsonResponse "modified_by.login" To sModified_byLogin
    Get ComIsNullOf Of hoJsonResponse "trashed_at" To iTrashed_at
    Get ComIsNullOf Of hoJsonResponse "purged_at" To iPurged_at
    Get ComStringOf Of hoJsonResponse "content_created_at" To sContent_created_at
    Get ComStringOf Of hoJsonResponse "content_modified_at" To sContent_modified_at
    Get ComStringOf Of hoJsonResponse "owned_by.type" To sOwned_byType
    Get ComStringOf Of hoJsonResponse "owned_by.id" To sOwned_byId
    Get ComStringOf Of hoJsonResponse "owned_by.name" To sOwned_byName
    Get ComStringOf Of hoJsonResponse "owned_by.login" To sOwned_byLogin
    Get ComIsNullOf Of hoJsonResponse "shared_link" To iShared_link
    Get ComIsNullOf Of hoJsonResponse "folder_upload_email" To iFolder_upload_email
    Get ComStringOf Of hoJsonResponse "parent.type" To sParentType
    Get ComStringOf Of hoJsonResponse "parent.id" To sParentId
    Get ComIsNullOf Of hoJsonResponse "parent.sequence_id" To iParentSequence_id
    Get ComIsNullOf Of hoJsonResponse "parent.etag" To iParentEtag
    Get ComStringOf Of hoJsonResponse "parent.name" To sParentName
    Get ComStringOf Of hoJsonResponse "item_status" To sItem_status
    Get ComIntOf Of hoJsonResponse "item_collection.total_count" To iItem_collectionTotal_count
    Get ComIntOf Of hoJsonResponse "item_collection.offset" To iItem_collectionOffset
    Get ComIntOf Of hoJsonResponse "item_collection.limit" To iItem_collectionLimit
    Move 0 To i
    Get ComSizeOfArray Of hoJsonResponse "path_collection.entries" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonResponse To i
        Get ComStringOf Of hoJsonResponse "path_collection.entries[i].type" To sType
        Get ComStringOf Of hoJsonResponse "path_collection.entries[i].id" To sId
        Get ComIsNullOf Of hoJsonResponse "path_collection.entries[i].sequence_id" To iSequence_id_bool
        Get ComIsNullOf Of hoJsonResponse "path_collection.entries[i].etag" To iEtag_bool
        Get ComStringOf Of hoJsonResponse "path_collection.entries[i].name" To sName
        Move i + 1 To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJsonResponse "item_collection.entries" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonResponse To i
        Move i + 1 To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJsonResponse "item_collection.order" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJsonResponse To i
        Get ComStringOf Of hoJsonResponse "item_collection.order[i].by" To sBy
        Get ComStringOf Of hoJsonResponse "item_collection.order[i].direction" To sDirection
        Move i + 1 To i
    Loop



End_Procedure

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"
      }
    ]
  }
}