Maybe you must check that you are receiving a folder or an album, and not a file, because I think that you cant browse for files in a file.
i.e
if (folder.type == 'folder' || folder.type == 'album')
if (folder.name == 'FooBar') { //do the call }
before you calling the next api request.
Try if that helps