Visual FoxPro Box: Create Folder

Back to Index

Creates a new folder. To create a folder in the root folder, use a parent folder id = "0".

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

CURL Command

curl https://api.box.com/2.0/folders \
-H "Authorization: Bearer BOX_ACCESS_TOKEN" \
-d '{"name":"Important Docs", "parent": {"id": "BOX_FOLDER_ID"}}' \
-X POST

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL loJsonResponse
LOCAL lcType
LOCAL lcId
LOCAL lcSequence_id
LOCAL lcEtag
LOCAL lcName
LOCAL lcCreated_at
LOCAL lcModified_at
LOCAL lcDescription
LOCAL lnSize
LOCAL lnPath_collectionTotal_count
LOCAL lcCreated_byType
LOCAL lcCreated_byId
LOCAL lcCreated_byName
LOCAL lcCreated_byLogin
LOCAL lcModified_byType
LOCAL lcModified_byId
LOCAL lcModified_byName
LOCAL lcModified_byLogin
LOCAL lnTrashed_at
LOCAL lnPurged_at
LOCAL lcContent_created_at
LOCAL lcContent_modified_at
LOCAL lcOwned_byType
LOCAL lcOwned_byId
LOCAL lcOwned_byName
LOCAL lcOwned_byLogin
LOCAL lnShared_link
LOCAL lnFolder_upload_email
LOCAL lcParentType
LOCAL lcParentId
LOCAL lnParentSequence_id
LOCAL lnParentEtag
LOCAL lcParentName
LOCAL lcItem_status
LOCAL lnItem_collectionTotal_count
LOCAL lnItem_collectionOffset
LOCAL lnItem_collectionLimit
LOCAL i
LOCAL lnCount_i
LOCAL lnSequence_id_bool
LOCAL lnEtag_bool
LOCAL lcBy
LOCAL lcDirection

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.box.com/2.0/folders
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("api.box.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("name","Important Docs")
loJson.UpdateString("parent.id","BOX_FOLDER_ID")

loRest.AddHeader("Authorization","Bearer BOX_ACCESS_TOKEN")

loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/2.0/folders",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)

lcType = loJsonResponse.StringOf("type")
lcId = loJsonResponse.StringOf("id")
lcSequence_id = loJsonResponse.StringOf("sequence_id")
lcEtag = loJsonResponse.StringOf("etag")
lcName = loJsonResponse.StringOf("name")
lcCreated_at = loJsonResponse.StringOf("created_at")
lcModified_at = loJsonResponse.StringOf("modified_at")
lcDescription = loJsonResponse.StringOf("description")
lnSize = loJsonResponse.IntOf("size")
lnPath_collectionTotal_count = loJsonResponse.IntOf("path_collection.total_count")
lcCreated_byType = loJsonResponse.StringOf("created_by.type")
lcCreated_byId = loJsonResponse.StringOf("created_by.id")
lcCreated_byName = loJsonResponse.StringOf("created_by.name")
lcCreated_byLogin = loJsonResponse.StringOf("created_by.login")
lcModified_byType = loJsonResponse.StringOf("modified_by.type")
lcModified_byId = loJsonResponse.StringOf("modified_by.id")
lcModified_byName = loJsonResponse.StringOf("modified_by.name")
lcModified_byLogin = loJsonResponse.StringOf("modified_by.login")
lnTrashed_at = loJsonResponse.IsNullOf("trashed_at")
lnPurged_at = loJsonResponse.IsNullOf("purged_at")
lcContent_created_at = loJsonResponse.StringOf("content_created_at")
lcContent_modified_at = loJsonResponse.StringOf("content_modified_at")
lcOwned_byType = loJsonResponse.StringOf("owned_by.type")
lcOwned_byId = loJsonResponse.StringOf("owned_by.id")
lcOwned_byName = loJsonResponse.StringOf("owned_by.name")
lcOwned_byLogin = loJsonResponse.StringOf("owned_by.login")
lnShared_link = loJsonResponse.IsNullOf("shared_link")
lnFolder_upload_email = loJsonResponse.IsNullOf("folder_upload_email")
lcParentType = loJsonResponse.StringOf("parent.type")
lcParentId = loJsonResponse.StringOf("parent.id")
lnParentSequence_id = loJsonResponse.IsNullOf("parent.sequence_id")
lnParentEtag = loJsonResponse.IsNullOf("parent.etag")
lcParentName = loJsonResponse.StringOf("parent.name")
lcItem_status = loJsonResponse.StringOf("item_status")
lnItem_collectionTotal_count = loJsonResponse.IntOf("item_collection.total_count")
lnItem_collectionOffset = loJsonResponse.IntOf("item_collection.offset")
lnItem_collectionLimit = loJsonResponse.IntOf("item_collection.limit")
i = 0
lnCount_i = loJsonResponse.SizeOfArray("path_collection.entries")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcType = loJsonResponse.StringOf("path_collection.entries[i].type")
    lcId = loJsonResponse.StringOf("path_collection.entries[i].id")
    lnSequence_id_bool = loJsonResponse.IsNullOf("path_collection.entries[i].sequence_id")
    lnEtag_bool = loJsonResponse.IsNullOf("path_collection.entries[i].etag")
    lcName = loJsonResponse.StringOf("path_collection.entries[i].name")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("item_collection.entries")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("item_collection.order")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcBy = loJsonResponse.StringOf("item_collection.order[i].by")
    lcDirection = loJsonResponse.StringOf("item_collection.order[i].direction")
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJsonResponse

Sample JSON Response Body

{
  "type": "folder",
  "id": "47885473705",
  "sequence_id": "0",
  "etag": "0",
  "name": "Important Docs",
  "created_at": "2018-03-16T06:54:57-07:00",
  "modified_at": "2018-03-16T06:54:57-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-16T06:54:57-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"
      }
    ]
  }
}