Box: Delete File
Deletes files on Box. You can delete multiple files at once. When you delete multiple files, you should write one file ID per line.
Configs: Common
  • Step Name
  • Note
Configs
  • C1: OAuth2 Setting *
  • C2: Data Item with File IDs to delete *
Script (click to open)

main();
function main(){
  const fileIds = engine.findDataByNumber(configs.get("conf_FileIds"));
  if (fileIds === "" ||fileIds === null){
    throw "File IDs aren't set.";
  }

  let linesArray = fileIds.split("\n");
  linesArray = linesArray.filter(lines => lines !== ""); // 空文字列を削除
  if (linesArray.length === 0) {
    throw "File IDs aren't set.";
  }

  const numOfLines = linesArray.length;
  if (numOfLines > httpClient.getRequestingLimit()){
  	throw "Number of File IDs is over the limit."
  }
  const oauth2 = configs.get("conf_OAuth2");
  for (let i = 0; i < numOfLines; i++){
    deleteFile(oauth2, linesArray[i])
  }
}

function deleteFile(oauth2, fileId) {
  const url = `https://api.box.com/2.0/files/${fileId}`;

  const response = httpClient.begin()
    .authSetting(oauth2)
    .delete(url);
    
  const status = response.getStatusCode();
  const responseTxt = response.getResponseAsString();
  engine.log(`status: ${status}`);
  if (status >= 300) {
    engine.log(responseTxt)
    throw `Failed to delete File ID:${fileId}`;
  }else{
    engine.log(`Succeeded to delete File ID:${fileId}`);
  }
}

Notes

Capture

See also

Intermediate Error Catch Event (Boundary Type)

Appendix

  • box-file-delete.xml (C) Questetra, Inc. (MIT License)
    • If you are using Professional, you can modify the contents of this file and use it as your own add-on
%d bloggers like this: