Box API node.js how to delete folder and display all files inclusive folders

十年热恋 提交于 2019-12-12 04:15:17

问题


I need working sample codes for delete a folder and list all items + folders in the root. I use node.js and as example I can create folder with

client.folders.create('0', 'New Folder', function(err, newFolder) {
if(err) throw err;
console.log('dff')
});

But if I try then related to docs client.folders.delete

client.folders.delete('0', 'New Folder', function(err, newFolder) {
 if(err) throw err;
 console.log('dff')
});

I get error "Unexpected API Response [403 Forbidden] (access_denied_insufficient_permissions: "Access denied - insufficient permission")". If I would remove 0 then I get rejection error.


回答1:


var client = sdk.getAppAuthClient('enterprise', ENTERPRISE_ID);

client.folders.getItems('0', null, function(err, items) {
  items.entries.forEach(function(element) {
  console.log(element)

  if (element.type == 'folder') {
      console.log('folder: ' + element.type);
      client.folders.delete(element.id, {recursive: true}, function(err, data) {
   });
  }
  else {
      console.log('file: ' + element.type);
      client.files.delete(element.id, {recursive: true}, function(err, data) {
     });
  }
  }, this);
})


来源:https://stackoverflow.com/questions/45517682/box-api-node-js-how-to-delete-folder-and-display-all-files-inclusive-folders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!