Skip to content

ABility to crawl the documents in BOX under a particular folder / enterprise level #271

Closed

Description

@Arvind6353

Hi Team ,

Is there a way I can crawl through the documents inside the Box folder .

Like get all the documents list inside a particular root folder .

Thanks,
Arvindan.

Activity

  1. carycheng commented on May 7, 2018

    @carycheng

    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.

  2. Arvind6353 commented on May 8, 2018

    @Arvind6353
    Author

    @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

  3. mattwiller commented on May 8, 2018

    @mattwiller

    @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!

  4. Arvind6353 commented on May 8, 2018

    @Arvind6353
    Author

    @mattwiller, OK thank you for the info.

  5. Arvind6353 commented on May 9, 2018

    @Arvind6353
    Author

    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

    LEt me know if am missing anything.

  6. mattwiller commented on May 9, 2018

    @mattwiller

    @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:

    let configFile = fs.readFileSync('./config.json');
    configFile = JSON.parse(configFile);
    let session = box.getPreconfiguredInstance(configFile);
    session.configure({ iterators: true });
    let serviceAccountClient = session.getAppAuthClient('enterprise','*****');
  7. Arvind6353 commented on May 10, 2018

    @Arvind6353
    Author

    @mattwiller : Thank you . It works :)

  8. mattwiller commented on May 10, 2018

    @mattwiller

    @Arvind6353 Great — I'm glad it's working for you now!

  9. Arvind6353 commented on May 14, 2018

    @Arvind6353
    Author

    @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

  10. mattwiller commented on May 14, 2018

    @mattwiller

    @Arvind6353 You can get the file's contents by downloading the file

  11. Arvind6353 commented on May 17, 2018

    @Arvind6353
    Author

    @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 .

  12. carycheng commented on May 17, 2018

    @carycheng

    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.

  13. carycheng commented on May 18, 2018

    @carycheng

    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

    client.events.getEnterpriseEventStream({
        eventTypeFilter: [client.events.enterpriseEventTypes.UPLOAD, client.events.enterpriseEventTypes.DOWNLOAD]
    }, callback);

    A full list of events to listen for can be found here

  14. Arvind6353 commented on May 18, 2018

    @Arvind6353
    Author

    @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.

  15. Arvind6353 commented on May 21, 2018

    @Arvind6353
    Author

    @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.

  16. mattwiller commented on May 24, 2018

    @mattwiller

    @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.

  17. Arvind6353 commented on May 24, 2018

    @Arvind6353
    Author

    @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.

  18. carycheng commented on May 24, 2018

    @carycheng

    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.

  19. winfeel commented on Dec 3, 2018

    @winfeel

    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?

  20. mattwiller commented on Dec 4, 2018

    @mattwiller

    @winfeel Could you please open a new issue with more detail on the problem you're seeing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions