Box: Delete File

Box: Delete File

Box: ファイル削除

This item deletes files on Box. You can delete multiple files at once. When you delete multiple files, you should write one file ID per line.

Auto Step icon
Basic Configs
Step Name
Note
Configs for this Auto Step
conf_OAuth2
C1: OAuth2 Setting *
conf_FileIds
C2: Data Item with File IDs to delete *

Notes

  • File ID is contained in the URL: https://app.box.com/file/(File ID)
  • Box refresh tokens have an expiration date

Capture

See Also

Script (click to open)
  • An XML file that contains the code below is available to download
    • 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 auto step

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.getObject("conf_OAuth2");
    for (let i = 0; i < numOfLines; i++) {
        deleteFile(oauth2, linesArray[i])
    }
}

/**
  * ファイルを削除する
  * @param {AuthSettingWrapper} oauth2 OAuth2 設定
  * @param {String} fileId ファイル ID
  */
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();
    if (status >= 300) {
        engine.log(responseTxt)
        throw `Failed to delete. File ID: ${fileId}, status: ${status}`;
    } else {
        engine.log(`Succeeded to delete. File ID: ${fileId}`);
    }
}
Scroll to Top

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading