PureBasic Box: Get Folder Collaborations

Back to Index

Returns all of the folder's collaborations. This API does not support paging -- it always returns all of the collaborations. Each collaboration object has details on which user or group has access to the file and with what role.

Documentation: https://developer.box.com/reference#view-a-folders-collaborations

CURL Command

curl https://api.box.com/2.0/folders/FOLDER_ID/collaborations \
-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/FOLDER_ID/collaborations
    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/FOLDER_ID/collaborations",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)

    total_count.i
    i.i
    count_i.i
    type.s
    id.s
    created_byType.s
    created_byId.s
    created_byName.s
    created_byLogin.s
    created_at.s
    modified_at.s
    expires_at.i
    status.s
    accessible_byType.s
    accessible_byId.s
    accessible_byName.s
    accessible_byLogin.s
    role.s
    acknowledged_at.s
    item.i

    total_count = CkJsonObject::ckIntOf(jsonResponse,"total_count")
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"entries")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        type = CkJsonObject::ckStringOf(jsonResponse,"entries[i].type")
        id = CkJsonObject::ckStringOf(jsonResponse,"entries[i].id")
        created_byType = CkJsonObject::ckStringOf(jsonResponse,"entries[i].created_by.type")
        created_byId = CkJsonObject::ckStringOf(jsonResponse,"entries[i].created_by.id")
        created_byName = CkJsonObject::ckStringOf(jsonResponse,"entries[i].created_by.name")
        created_byLogin = CkJsonObject::ckStringOf(jsonResponse,"entries[i].created_by.login")
        created_at = CkJsonObject::ckStringOf(jsonResponse,"entries[i].created_at")
        modified_at = CkJsonObject::ckStringOf(jsonResponse,"entries[i].modified_at")
        expires_at = CkJsonObject::ckIsNullOf(jsonResponse,"entries[i].expires_at")
        status = CkJsonObject::ckStringOf(jsonResponse,"entries[i].status")
        accessible_byType = CkJsonObject::ckStringOf(jsonResponse,"entries[i].accessible_by.type")
        accessible_byId = CkJsonObject::ckStringOf(jsonResponse,"entries[i].accessible_by.id")
        accessible_byName = CkJsonObject::ckStringOf(jsonResponse,"entries[i].accessible_by.name")
        accessible_byLogin = CkJsonObject::ckStringOf(jsonResponse,"entries[i].accessible_by.login")
        role = CkJsonObject::ckStringOf(jsonResponse,"entries[i].role")
        acknowledged_at = CkJsonObject::ckStringOf(jsonResponse,"entries[i].acknowledged_at")
        item = CkJsonObject::ckIsNullOf(jsonResponse,"entries[i].item")
        i = i + 1
    Wend


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


    ProcedureReturn
EndProcedure

Sample JSON Response Body

{
  "total_count": 1,
  "entries": [
    {
      "type": "collaboration",
      "id": "14176246",
      "created_by": {
        "type": "user",
        "id": "4276790",
        "name": "David Lee",
        "login": "david@box.com"
      },
      "created_at": "2011-11-29T12:56:35-08:00",
      "modified_at": "2012-09-11T15:12:32-07:00",
      "expires_at": null,
      "status": "accepted",
      "accessible_by": {
        "type": "user",
        "id": "755492",
        "name": "Simon Tan",
        "login": "simon@box.net"
      },
      "role": "editor",
      "acknowledged_at": "2011-11-29T12:59:40-08:00",
      "item": null
    }
  ]
}