
Box: Apply Watermark to Folder
This item applies watermark to all files in the specified folder on Box.
Basic Configs
- Step Name
- Note
Configs for this Auto Step
- conf_OAuth2
- C1: OAuth2 Setting *
- conf_FolderId
- 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 creating and sharing a link to a folder with an electronic watermark applied, it will not be possible to download or preview the watermarked folder (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 auto step
function main(){
const oauth2 = configs.getObject("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 {AuthSettingWrapper} oauth2 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}`;
}
}