You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ABility to crawl the documents in BOX under a particular folder / enterprise level #271
You would use the ID '0' to indicate that it's the root folder you want to retrieve all items for. To dig into a particular folder you will need to save that folder's particular ID and pass that into the folder.getItems() method again.
@carycheng,
So its like making recursive calls of folders.getItems(folderID, options, callback) on the each of the folders present inside the root folder . Am I right ?.
Do you have any sample code for the above scenario ?
@Arvind6353 That sounds correct to me. Unfortunately, we don't have a code sample for this — it should be relatively straightforward though. You may want to use the iterators functionality provided by the SDK to make this easier!
Hi I tried using the iterators .
PFB the settings :
"boxAppSettings": {
"clientID": "xxxxxx",
"clientSecret": "xxxxx",
"iterators": true,
"appAuth": {
"publicKeyID": "xxxx",
"privateKey": "xxxxx",
"passphrase": "xxxxx"
}
},
"enterpriseID": "xxxxx",
"webhooks": {
"secondaryKey": "xxxxx"
}
}
The above config is placed in a json file config.json
let configFile = fs.readFileSync('./config.json');
configFile = JSON.parse(configFile);
let session = box.getPreconfiguredInstance(configFile);
let serviceAccountClient = session.getAppAuthClient('enterprise','*****');
**serviceAccountClient.folders.getItems('folDerID').then(it => {
console.log("iterator result ",it);
// Output all items in the folder using a recursive promise chain which
// prints each item from the iterator until done
function printAllItems() {
// Get the next item from the iterator
return it.next().then(res => {
if (res.done) return;
console.log(res.value);
// Recurse to get the next item
return printAllItems();
})
}
printAllItems();
});**
When I run this am getting Unhandled rejection TypeError: it.next is not a function
@Arvind6353 The getPreconfiguredInstance() method is only designed to take the options from the JSON blob — it won't read any properties you add by hand. Instead, you'll need to do something like this:
@mattwiller : Thanks . Have a query .
Am trying to build a search dashboard to display the box contents metadata.
I did fetch all the box folder items and I was able to extract info from them .
I am putting those details in a search server and using it for the search .
The problem I see is that , box search api searches inside the contents of the files and I am not able to do that .
Is there a way for leveraging something similar to search api that runs on a weekly basis to get all the details and put it to a search server .
(To get the contents of a file )
A function to get the contents of a file by fileId would be helpful as well.
Wanted to follow up with your use case of retrieving modified files. We generally discourage the use of the /search endpoint for scenarios such as this. In this case we encourage our users to use the Events endpoint.
You can use the Get Enterprise Events Stream like the snippet below
@carycheng@mattwiller
Is there a way to subscribe to events only on a particular root folder .
The getEnterpriseEventStream method returns events from folders that the service account is not collaborating with but from the whole enterprise .
When I do say getFolderItems , the results are from only those specific folders to which the service account has been added as a collaborator.
@Arvind6353 You could try listening to the user events stream for just the events pertaining to the service account and the folders it's collaborated on.
Unfortunately there is no way to do that directly via the Box API today. You will have to manually read the event stream and filter out relevant folder modifications.
Hey, it seems I cannot get file extraction working when assigning limit to None. When it is set at a fixed number, it works. Anyone able to enlighten me on that?
Activity
carycheng commentedon May 7, 2018
Hey @Arvind6353,
To retrieve all folder items inside a particular Box folder you can use the
folders.getItems(folderID, options, callback)call.You would use the ID '0' to indicate that it's the root folder you want to retrieve all items for. To dig into a particular folder you will need to save that folder's particular ID and pass that into the
folder.getItems()method again.Arvind6353 commentedon May 8, 2018
@carycheng,
So its like making recursive calls of folders.getItems(folderID, options, callback) on the each of the folders present inside the root folder . Am I right ?.
Do you have any sample code for the above scenario ?
Thanks,
Arvind
mattwiller commentedon May 8, 2018
@Arvind6353 That sounds correct to me. Unfortunately, we don't have a code sample for this — it should be relatively straightforward though. You may want to use the iterators functionality provided by the SDK to make this easier!
Arvind6353 commentedon May 8, 2018
@mattwiller, OK thank you for the info.
Arvind6353 commentedon May 9, 2018
Hi I tried using the iterators .
PFB the settings :
"boxAppSettings": {
"clientID": "xxxxxx",
"clientSecret": "xxxxx",
"iterators": true,
"appAuth": {
"publicKeyID": "xxxx",
"privateKey": "xxxxx",
"passphrase": "xxxxx"
}
},
"enterpriseID": "xxxxx",
"webhooks": {
"secondaryKey": "xxxxx"
}
}
The above config is placed in a json file config.json
let configFile = fs.readFileSync('./config.json');
configFile = JSON.parse(configFile);
let session = box.getPreconfiguredInstance(configFile);
let serviceAccountClient = session.getAppAuthClient('enterprise','*****');
**serviceAccountClient.folders.getItems('folDerID').then(it => {
console.log("iterator result ",it);
// Output all items in the folder using a recursive promise chain which
// prints each item from the iterator until done
function printAllItems() {
When I run this am getting Unhandled rejection TypeError: it.next is not a function
LEt me know if am missing anything.
mattwiller commentedon May 9, 2018
@Arvind6353 The
getPreconfiguredInstance()method is only designed to take the options from the JSON blob — it won't read any properties you add by hand. Instead, you'll need to do something like this:Arvind6353 commentedon May 10, 2018
@mattwiller : Thank you . It works :)
mattwiller commentedon May 10, 2018
@Arvind6353 Great — I'm glad it's working for you now!
Arvind6353 commentedon May 14, 2018
@mattwiller : Thanks . Have a query .
Am trying to build a search dashboard to display the box contents metadata.
I did fetch all the box folder items and I was able to extract info from them .
I am putting those details in a search server and using it for the search .
The problem I see is that , box search api searches inside the contents of the files and I am not able to do that .
Is there a way for leveraging something similar to search api that runs on a weekly basis to get all the details and put it to a search server .
(To get the contents of a file )
A function to get the contents of a file by fileId would be helpful as well.
Thanks,
Arvind
mattwiller commentedon May 14, 2018
@Arvind6353 You can get the file's contents by downloading the file
Arvind6353 commentedon May 17, 2018
@mattwiller . Is there a way I can find the documents that are modified / created on a daily basis ?.
I see that the search query has an option to specify updated_range / created_range but it requires search string as mandatory field .
carycheng commentedon May 17, 2018
Hey @Arvind6353,
Unfortunately the search string is required so you will have to input a string in order to do a search along with the updated_at_range.
carycheng commentedon May 18, 2018
Hey @Arvind6353,
Wanted to follow up with your use case of retrieving modified files. We generally discourage the use of the /search endpoint for scenarios such as this. In this case we encourage our users to use the Events endpoint.
You can use the Get Enterprise Events Stream like the snippet below
A full list of events to listen for can be found here
Arvind6353 commentedon May 18, 2018
@carycheng. Thanks for the information. Let me try the events endpoint and get back in case of any issues. Thanks once again for ur time.
Arvind6353 commentedon May 21, 2018
@carycheng @mattwiller
Is there a way to subscribe to events only on a particular root folder .
The getEnterpriseEventStream method returns events from folders that the service account is not collaborating with but from the whole enterprise .
When I do say getFolderItems , the results are from only those specific folders to which the service account has been added as a collaborator.
mattwiller commentedon May 24, 2018
@Arvind6353 You could try listening to the user events stream for just the events pertaining to the service account and the folders it's collaborated on.
Arvind6353 commentedon May 24, 2018
@mattwiller : In client.events.getEventStream(function(err, stream) {
});
Am not able to find a way where I can specify the folders to get the events from ?
Is there any option for it ?
I need to only get the events from the folder(its children) for whom I have the folderId and the service account is added as an collaborator.
carycheng commentedon May 24, 2018
Hey @Arvind6353,
Unfortunately there is no way to do that directly via the Box API today. You will have to manually read the event stream and filter out relevant folder modifications.
winfeel commentedon Dec 3, 2018
Hey, it seems I cannot get file extraction working when assigning limit to None. When it is set at a fixed number, it works. Anyone able to enlighten me on that?
mattwiller commentedon Dec 4, 2018
@winfeel Could you please open a new issue with more detail on the problem you're seeing?