jhoerr / box-csharp-sdk-v2

A C# client for the Box API (v2).
http://developers.box.com/docs/
11 stars 15 forks source link

Error with GetFolder call #17

Closed mascon closed 11 years ago

mascon commented 11 years ago

When running the following code the SDK chokes on a valid folder ID

            Dim BoxUserClient As New BoxManager(BoxAccount.API_Key, UserAuthToken)

            Try

                Dim BoxFolderList = BoxUserClient.GetItems(Folder.Root)

                For Each FolderReturned In BoxFolderList.Entries

                    Dim Boxfolder = BoxUserClient.GetFolder(FolderReturned.Id)

                    If Boxfolder.OwnedBy.Id = BoxUsers.Entries(CurrentUserIndex).Id Then

                        intOwnerCounter += 1
                        strOwnerBoxIDs += "#" & Boxfolder.Id & "#"

                    Else

                        For Each collaboration In BoxUserClient.GetCollaborations(Boxfolder.Id).Entries

                            If collaboration.AccessibleBy.Id = BoxUsers.Entries(CurrentUserIndex).Id And collaboration.Role = CollaborationRole.CoOwner Then

                                intCoOwnerCounter += 1
                                strCoOwnerBoxIDs += "#" & Boxfolder.Id & "#"

                            End If

                        Next

                    End If

                Next

            Catch ex As BoxException

                Debug.Print(ex.Message)

            End Try

PostMan and the headers and folderID returns successfully.

jhoerr commented 11 years ago

BoxUserClient.GetItems(Folder.Root) returns all the items in the folder (not just the subfolders.) As a result I suspect the call is failing because you then end up executing GetFolder(id) with a file id.

For your purposes, this might work better:

Dim rootFolder = BoxUserClient.GetFolder(Folder.Root) For Each FolderReturned In rootFolder.Folders

mascon commented 11 years ago

Yep that solved the issue. I see the logic now. But I now have the same issue with the collaborations. Sometimes they come back empty too. How can a folder in a users root have no collaborations on it. It should at least have thier own.

I am basicly looking to see if the user is a owner or co-owner of any of the folders in their root tree. So I check all the returned folders for the owners value but for the co-ownership I have to check collaboration right?

And I receive a lot of nothings coming back on the folders. I have added a IsNothing check to stop it crashing.for now.

mascon commented 11 years ago

I did some more digging at the JSON response from box.

It does appear that you can get a collaboration with the AccessibleBy entry as NULL. That is very strange and I will discuss this with BOX to see if these are orphaned entries caused after a user is deleted.

As of now you can for me close this non issue and put it down to a fault between the chair and the desk :-)

jhoerr commented 11 years ago

As of now you can for me close this non issue

Ok, no problem! But real quick:

I receive a lot of nothings coming back on the folders. I have added a IsNothing check to stop it crashing.for now.

I'd like to learn more about what's happening here. Do you have a bit of code that will reproduce this?

mascon commented 11 years ago

Here is a sample response, I have changed the values in places to protect from spammers and hacker :-)

{
    "type": "collaboration",
    "id": "30735166",
    "created_by": {
        "type": "user",
        "id": "183923453",
        "name": "Mr A User",
        "login": "a-user@a-company.com"
    },
    "created_at": "2012-12-21T02:59:39-08:00",
    "modified_at": "2013-01-10T01:30:35-08:00",
    "expires_at": null,
    "status": "accepted",
    "accessible_by": null,
    "role": "editor",
    "acknowledged_at": "2013-01-10T01:30:35-08:00",
    "item": {
        "type": "folder",
        "id": "437870908",
        "sequence_id": "3",
        "etag": "3",
        "name": "ICT Customers"
    }
}

You will clearly see that the "accessible_by" value is NULL. I see no reason at all for this response from BOX and as such I will talk to the team about why they send this information in the JSON response.

Also I have noted that it makes no difference to the return information if I use

For Each collaboration In BoxUserClient.GetCollaborations(FolderReturned.Id).Entries

or

For Each collaboration In BoxUserClient.GetCollaborations(FolderReturned.Id, True).Entries

So maybe we have a bug here or Box is not listening to the request your sending.

prexer commented 11 years ago

Good catch John, We are looking into it.

jhoerr commented 11 years ago

That one was all Simon. :)