Box: Delete Folder

Box: Delete Folder
This item deletes folders on Box.
Configs: Common
  • Step Name
  • Note
Configs
  • C1: OAuth2 Setting *
  • C2: Folder IDs to delete (Write one per line) *

Notes

  • Folder ID is contained in the URL: https:// {sub-domain}.app.box.com/folder/(Folder ID)
  • The refresh token for Box has the expiration. Use regularly to ensure that it does not exceed the expiration. (Box: Token & URL Expiration)

Capture

See also

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


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

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

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

function deleteFolder(oauth2, folderId) {
    const url = `https://api.box.com/2.0/folders/${folderId}`;

    let response = httpClient.begin()
        .authSetting(oauth2)
        .queryParam("recursive", "true")
        .delete(url);
    const status = response.getStatusCode();
    const responseTxt = response.getResponseAsString();
    if (status >= 300) {
        engine.log(responseTxt);
        throw `Failed to delete. Folder ID:${folderId}, status: ${status}`;
    } else {
        engine.log(`Succeeded to delete. Folder ID:${folderId}`);
    }
}

1 thought on “Box: Delete Folder”

  1. Pingback: Utilising Box From Your Workflow – Questetra Support

Comments are closed.

Scroll to Top

Discover more from Questetra Support

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

Continue reading