Box: Apply Watermark to Folder
This item applies a watermark to all files in the specified folder on Box.
Configs: Common
  • Step Name
  • Note
Configs
  • C1: OAuth2 Setting *
  • C2: Folder ID to apply watermark to *

Notes

  • The folder ID is contained in the URL: https:// {sub-domain}.app.box.com/folder/(Folder ID)
  • Box refresh tokens have an expiration date. Use it regularly to ensure that it does not exceed the expiration (Box: Token & URL Expiration)
  • Users authenticating in the C1: OAuth2 Setting must have a Box enterprise user account
  • The added watermark is in the format {user email address – date, time, time zone} (e.g. “user@example.com – Jan 1, 2022, 9:00:00 AM PDT”)
    • The watermark will be applied to all files contained within the selected folder
    • Files added to the selected folder subsequently will have the watermark added automatically
  • If a password is set when ‘create a link and share, sharers will not be able to download or preview watermarked files (as of 2022-10-28)

Capture

See also

Script (click to open)
  • An XML file that contains the code below is available to download
    • box-folder-watermark-apply.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
  • If you set a password when creating a link and sharing a folder, sharer will not be able to download or preview files


main();
function main(){
    const oauth2 = configs.get('conf_OAuth2');
    const folderId = decideFolderId();
    applyWatermark(oauth2, folderId);
}

/**
  * フォルダ ID を config から読み出して出力する
  * @return {String} folderId フォルダ ID
  */
function decideFolderId(){
    const folderId = engine.findData(configs.getObject('conf_FolderId'));
    if (folderId === '' || folderId === null) {
        throw 'Folder ID is blank.';
    }
    return folderId;
}

/**
  * 電子すかしを適用
  * @param {String} oauth OAuth2 設定
  * @param {String} folderId フォルダ ID
  */
function applyWatermark(oauth2, folderId) {
    const jsonBody = {};
    jsonBody['watermark'] = {'imprint': 'default'};
    const url = `https://api.box.com/2.0/folders/${encodeURIComponent(folderId)}/watermark`;
    const response = httpClient.begin()
        .authSetting(oauth2)
        .body(JSON.stringify(jsonBody), 'application/json; charset=UTF-8')
        .put(url);
    const status = response.getStatusCode();
    if (status !== 200 && status !== 201) { // 200: 更新, 201: 新規適用
        engine.log(response.getResponseAsString());
        throw `Failed to apply watermark. status:${status}`;
    }
}

    
%d