Reputation: 854
Say I am assuming that my Box account has a folder called "TestFolder". I want to get the folder ID of that folder so I can write files to it from within my iOS app.
Is my only option to traverse the entire root of my Box account looking for that folder name? Something like this?
__block NSString *folderID;
BOXContentClient *contentClient = [BOXContentClient defaultClient];
BOXFolderItemsRequest *listAllInRoot = [contentClient folderItemsRequestWithID:BOXAPIFolderIDRoot];
[listAllInRoot performRequestWithCompletion:^(NSArray *items, NSError *error) {
if (error != nil) {
NSLog(@"Something bad happened when listing Box contents.");
return;
}
int ii,nItems = (int) [items count];
for (ii=0; ii<nItems; ii++) {
BOXItem *currItem = [items objectAtIndex:ii];
if ([[currItem name] isEqualToString:@"TestFolder"] && [currItem isFolder]) {
folderID = [currItem modelID];
break;
}
}
}];
Upvotes: 2
Views: 523
Reputation: 1214
You can use the Box API search endpoint to query a folder by name. If the search endpoint finds the folder, the response will include the folder's id.
Here is an example that shows how to make this call with the Box iOS SDK:
BOXContentClient *contentClient = [BOXContentClient defaultClient];
BOXSearchRequest *searchRequest = [contentClient searchRequestWithQuery:@"Test Folder" inRange:NSMakeRange(0, 1000)];
[searchRequest performRequestWithCompletion:^(NSArray *items, NSUInteger totalCount, NSRange range, NSError *error) {
// If successful, items will be non-nil and contain BOXItem model objects; otherwise, error will be non-nil.
}];
Upvotes: 1