PureBasic 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" \

PureBasic Example

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"

Procedure ChilkatExample()

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ;  URL: https://api.box.com/2.0/folders/0
    bTls.i = 1
    port.i = 443
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"api.box.com",port,bTls,bAutoReconnect)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    CkRest::ckAddHeader(rest,"Authorization","Bearer BOX_ACCESS_TOKEN")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkRest::ckFullRequestNoBodySb(rest,"GET","/2.0/folders/0",sbResponseBody)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jsonResponse.i = CkJsonObject::ckCreate()
    If jsonResponse.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jsonResponse,sbResponseBody)

    type.s
    id.s
    sequence_id.i
    etag.i
    name.s
    created_at.i
    modified_at.i
    description.s
    size.i
    path_collectionTotal_count.i
    created_byType.s
    created_byId.s
    created_byName.s
    created_byLogin.s
    modified_byType.s
    modified_byId.s
    modified_byName.s
    modified_byLogin.s
    trashed_at.i
    purged_at.i
    content_created_at.i
    content_modified_at.i
    owned_byType.s
    owned_byId.s
    owned_byName.s
    owned_byLogin.s
    shared_link.i
    folder_upload_email.i
    parent.i
    item_status.s
    item_collectionTotal_count.i
    item_collectionOffset.i
    item_collectionLimit.i
    i.i
    count_i.i
    file_versionType.s
    file_versionId.s
    file_versionSha1.s
    sequence_id_str.s
    etag_str.s
    sha1.s
    by.s
    direction.s

    type = CkJsonObject::ckStringOf(jsonResponse,"type")
    id = CkJsonObject::ckStringOf(jsonResponse,"id")
    sequence_id = CkJsonObject::ckIsNullOf(jsonResponse,"sequence_id")
    etag = CkJsonObject::ckIsNullOf(jsonResponse,"etag")
    name = CkJsonObject::ckStringOf(jsonResponse,"name")
    created_at = CkJsonObject::ckIsNullOf(jsonResponse,"created_at")
    modified_at = CkJsonObject::ckIsNullOf(jsonResponse,"modified_at")
    description = CkJsonObject::ckStringOf(jsonResponse,"description")
    size = CkJsonObject::ckIntOf(jsonResponse,"size")
    path_collectionTotal_count = CkJsonObject::ckIntOf(jsonResponse,"path_collection.total_count")
    created_byType = CkJsonObject::ckStringOf(jsonResponse,"created_by.type")
    created_byId = CkJsonObject::ckStringOf(jsonResponse,"created_by.id")
    created_byName = CkJsonObject::ckStringOf(jsonResponse,"created_by.name")
    created_byLogin = CkJsonObject::ckStringOf(jsonResponse,"created_by.login")
    modified_byType = CkJsonObject::ckStringOf(jsonResponse,"modified_by.type")
    modified_byId = CkJsonObject::ckStringOf(jsonResponse,"modified_by.id")
    modified_byName = CkJsonObject::ckStringOf(jsonResponse,"modified_by.name")
    modified_byLogin = CkJsonObject::ckStringOf(jsonResponse,"modified_by.login")
    trashed_at = CkJsonObject::ckIsNullOf(jsonResponse,"trashed_at")
    purged_at = CkJsonObject::ckIsNullOf(jsonResponse,"purged_at")
    content_created_at = CkJsonObject::ckIsNullOf(jsonResponse,"content_created_at")
    content_modified_at = CkJsonObject::ckIsNullOf(jsonResponse,"content_modified_at")
    owned_byType = CkJsonObject::ckStringOf(jsonResponse,"owned_by.type")
    owned_byId = CkJsonObject::ckStringOf(jsonResponse,"owned_by.id")
    owned_byName = CkJsonObject::ckStringOf(jsonResponse,"owned_by.name")
    owned_byLogin = CkJsonObject::ckStringOf(jsonResponse,"owned_by.login")
    shared_link = CkJsonObject::ckIsNullOf(jsonResponse,"shared_link")
    folder_upload_email = CkJsonObject::ckIsNullOf(jsonResponse,"folder_upload_email")
    parent = CkJsonObject::ckIsNullOf(jsonResponse,"parent")
    item_status = CkJsonObject::ckStringOf(jsonResponse,"item_status")
    item_collectionTotal_count = CkJsonObject::ckIntOf(jsonResponse,"item_collection.total_count")
    item_collectionOffset = CkJsonObject::ckIntOf(jsonResponse,"item_collection.offset")
    item_collectionLimit = CkJsonObject::ckIntOf(jsonResponse,"item_collection.limit")
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"path_collection.entries")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"item_collection.entries")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        type = CkJsonObject::ckStringOf(jsonResponse,"item_collection.entries[i].type")
        id = CkJsonObject::ckStringOf(jsonResponse,"item_collection.entries[i].id")
        file_versionType = CkJsonObject::ckStringOf(jsonResponse,"item_collection.entries[i].file_version.type")
        file_versionId = CkJsonObject::ckStringOf(jsonResponse,"item_collection.entries[i].file_version.id")
        file_versionSha1 = CkJsonObject::ckStringOf(jsonResponse,"item_collection.entries[i].file_version.sha1")
        sequence_id_str = CkJsonObject::ckStringOf(jsonResponse,"item_collection.entries[i].sequence_id")
        etag_str = CkJsonObject::ckStringOf(jsonResponse,"item_collection.entries[i].etag")
        sha1 = CkJsonObject::ckStringOf(jsonResponse,"item_collection.entries[i].sha1")
        name = CkJsonObject::ckStringOf(jsonResponse,"item_collection.entries[i].name")
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"item_collection.order")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        by = CkJsonObject::ckStringOf(jsonResponse,"item_collection.order[i].by")
        direction = CkJsonObject::ckStringOf(jsonResponse,"item_collection.order[i].direction")
        i = i + 1
    Wend


    CkRest::ckDispose(rest)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jsonResponse)


    ProcedureReturn
EndProcedure

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