Visual FoxPro Box: Get Root Folder Info

Back to Index

Gets the folder info for the root folder of a Box.com account. The root folder of a box.com account always has an id = "0".

Documentation: https://developer.box.com/reference#get-folder-info

CURL Command

curl https://api.box.com/2.0/folders/0 \
-H "Authorization: Bearer BOX_ACCESS_TOKEN" \

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL loJsonResponse
LOCAL lcType
LOCAL lcId
LOCAL lnSequence_id
LOCAL lnEtag
LOCAL lcName
LOCAL lnCreated_at
LOCAL lnModified_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 lnContent_created_at
LOCAL lnContent_modified_at
LOCAL lcOwned_byType
LOCAL lcOwned_byId
LOCAL lcOwned_byName
LOCAL lcOwned_byLogin
LOCAL lnShared_link
LOCAL lnFolder_upload_email
LOCAL lnParent
LOCAL lcItem_status
LOCAL lnItem_collectionTotal_count
LOCAL lnItem_collectionOffset
LOCAL lnItem_collectionLimit
LOCAL i
LOCAL lnCount_i
LOCAL lcFile_versionType
LOCAL lcFile_versionId
LOCAL lcFile_versionSha1
LOCAL lcSequence_id_str
LOCAL lcEtag_str
LOCAL lcSha1
LOCAL lcBy
LOCAL lcDirection

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.box.com/2.0/folders/0
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

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

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/2.0/folders/0",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loSbResponseBody
    CANCEL
ENDIF

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

lcType = loJsonResponse.StringOf("type")
lcId = loJsonResponse.StringOf("id")
lnSequence_id = loJsonResponse.IsNullOf("sequence_id")
lnEtag = loJsonResponse.IsNullOf("etag")
lcName = loJsonResponse.StringOf("name")
lnCreated_at = loJsonResponse.IsNullOf("created_at")
lnModified_at = loJsonResponse.IsNullOf("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")
lnContent_created_at = loJsonResponse.IsNullOf("content_created_at")
lnContent_modified_at = loJsonResponse.IsNullOf("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")
lnParent = loJsonResponse.IsNullOf("parent")
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
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("item_collection.entries")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcType = loJsonResponse.StringOf("item_collection.entries[i].type")
    lcId = loJsonResponse.StringOf("item_collection.entries[i].id")
    lcFile_versionType = loJsonResponse.StringOf("item_collection.entries[i].file_version.type")
    lcFile_versionId = loJsonResponse.StringOf("item_collection.entries[i].file_version.id")
    lcFile_versionSha1 = loJsonResponse.StringOf("item_collection.entries[i].file_version.sha1")
    lcSequence_id_str = loJsonResponse.StringOf("item_collection.entries[i].sequence_id")
    lcEtag_str = loJsonResponse.StringOf("item_collection.entries[i].etag")
    lcSha1 = loJsonResponse.StringOf("item_collection.entries[i].sha1")
    lcName = loJsonResponse.StringOf("item_collection.entries[i].name")
    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 loSbResponseBody
RELEASE loJsonResponse

Sample JSON Response Body

{
  "type": "folder",
  "id": "0",
  "sequence_id": null,
  "etag": null,
  "name": "All Files",
  "created_at": null,
  "modified_at": null,
  "description": "",
  "size": 826408,
  "path_collection": {
    "total_count": 0,
    "entries": [
    ]
  },
  "created_by": {
    "type": "user",
    "id": "",
    "name": "",
    "login": ""
  },
  "modified_by": {
    "type": "user",
    "id": "2787704945",
    "name": "chilkat",
    "login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
  },
  "trashed_at": null,
  "purged_at": null,
  "content_created_at": null,
  "content_modified_at": null,
  "owned_by": {
    "type": "user",
    "id": "2787704945",
    "name": "chilkat",
    "login": "AutomationUser_434741_3nmGYSS7o5@@boxdevedition.com"
  },
  "shared_link": null,
  "folder_upload_email": null,
  "parent": null,
  "item_status": "active",
  "item_collection": {
    "total_count": 2,
    "entries": [
      {
        "type": "file",
        "id": "246181882790",
        "file_version": {
          "type": "file_version",
          "id": "259636211878",
          "sha1": "c9d2492fb97f88a9b4d1e35f32a3410e95853f18"
        },
        "sequence_id": "0",
        "etag": "0",
        "sha1": "c9d2492fb97f88a9b4d1e35f32a3410e95853f18",
        "name": "hedgehogs.jpg"
      },
      {
        "type": "file",
        "id": "246167973161",
        "file_version": {
          "type": "file_version",
          "id": "259621592361",
          "sha1": "df7be9dc4f467187783aca68c7ce98e4df2172d0"
        },
        "sequence_id": "0",
        "etag": "0",
        "sha1": "df7be9dc4f467187783aca68c7ce98e4df2172d0",
        "name": "penguins.jpg"
      }
    ],
    "offset": 0,
    "limit": 100,
    "order": [
      {
        "by": "type",
        "direction": "ASC"
      },
      {
        "by": "name",
        "direction": "ASC"
      }
    ]
  }
}