BoxInspect
Changes
index.js 11(+9 -2)
Details
index.js 11(+9 -2)
diff --git a/index.js b/index.js
index 1676d2d..765dd41 100644
--- a/index.js
+++ b/index.js
@@ -15,8 +15,15 @@ const client = sdk.getBasicClient(process.env.DEV_TOKEN);
const rootFolders = []
const getFolders = async (id) => {
- const r = await client.folders.get(id)
- const folderIds = r.item_collection.entries.filter(f => f.type === 'folder').map(f => f.id)
+ const r = await client.folders.get(id, {limit: 1})
+ const chunks = 100
+ const iterations = Math.floor(r.item_collection.total_count / chunks)
+ const folderIds = []
+ for (let i = 0; i <= iterations; i++) {
+ let items = await client.folders.get(id, {limit: chunks, offset: (chunks * i)})
+ let parts = items.item_collection.entries.filter(f => f.type === 'folder').map(f => f.id)
+ folderIds.push(...parts)
+ }
if (folderIds.length === 0) {
rootFolders.push(id)
return