Visual FoxPro Box: Get Folder Items

Back to Index

Gets all of the files, folders, or web links contained within a folder.

Documentation: https://developer.box.com/reference#get-a-folders-items

CURL Command

curl https://api.box.com/2.0/folders/BOX_FOLDER_ID/items?limit=2&offset=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 lnTotal_count
LOCAL lnOffset
LOCAL lnLimit
LOCAL i
LOCAL lnCount_i
LOCAL lcType
LOCAL lcId
LOCAL lcFile_versionType
LOCAL lcFile_versionId
LOCAL lcFile_versionSha1
LOCAL lcSequence_id
LOCAL lcEtag
LOCAL lcSha1
LOCAL lcName
LOCAL lcBy
LOCAL lcDirection

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.box.com/2.0/folders/BOX_FOLDER_ID/items?limit=2&offset=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/BOX_FOLDER_ID/items?limit=2&offset=0",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loSbResponseBody
    CANCEL
ENDIF

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

lnTotal_count = loJsonResponse.IntOf("total_count")
lnOffset = loJsonResponse.IntOf("offset")
lnLimit = loJsonResponse.IntOf("limit")
i = 0
lnCount_i = loJsonResponse.SizeOfArray("entries")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcType = loJsonResponse.StringOf("entries[i].type")
    lcId = loJsonResponse.StringOf("entries[i].id")
    lcFile_versionType = loJsonResponse.StringOf("entries[i].file_version.type")
    lcFile_versionId = loJsonResponse.StringOf("entries[i].file_version.id")
    lcFile_versionSha1 = loJsonResponse.StringOf("entries[i].file_version.sha1")
    lcSequence_id = loJsonResponse.StringOf("entries[i].sequence_id")
    lcEtag = loJsonResponse.StringOf("entries[i].etag")
    lcSha1 = loJsonResponse.StringOf("entries[i].sha1")
    lcName = loJsonResponse.StringOf("entries[i].name")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("order")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcBy = loJsonResponse.StringOf("order[i].by")
    lcDirection = loJsonResponse.StringOf("order[i].direction")
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

Sample JSON Response Body

{
  "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": 2,
  "order": [
    {
      "by": "type",
      "direction": "ASC"
    },
    {
      "by": "name",
      "direction": "ASC"
    }
  ]
}