

Box: ファイル共有リンク削除
Box: Delete Shared Link of File
この工程は、Box 上の指定ファイルの共有リンク URL を削除します。共有リンクが無い場合は、エラーとなります。
Basic Configs
- 工程名
- メモ
Configs for this Auto Step
- conf_OAuth2
- C1: OAuth2 設定 *
- conf_FileId
- C2: 共有リンクを削除するファイルの ID *
Notes
- ファイルID は、URL に含まれています https://{sub-domain}.app.box.com/file/(File ID)
- Box のリフレッシュトークンには、期限があります
- 期限を超えないよう、定期的に利用する必要があります (Box: トークンおよびURLの有効期限)
- 共有リンクが無い場合は、エラーとなります
Capture

See also
Script (click to open)
- 次のスクリプトが記述されている XML ファイルをダウンロードできます
- box-file-link-delete.xml (C) Questetra, Inc. (MIT License)
- Professional のワークフロー基盤では、ファイル内容を改変しオリジナルのアドオン自動工程として活用できます
function main() {
const oauth2 = configs.getObject("conf_OAuth2");
const fileId = decideFileId();
checkExistingSharedLink(oauth2, fileId);
deleteSharedLink(oauth2, fileId);
}
/**
* ファイルのIDをconfigから読み出して出力する。
* @return {String} fileId ファイルの ID
*/
function decideFileId() {
let fileId = "";
const fileIdDef = configs.getObject("conf_FileId");
if (fileIdDef === null) {
fileId = configs.get("conf_FileId");
} else {
fileId = engine.findData(fileIdDef);
}
if (fileId === "" || fileId === null) {
throw "File ID is blank";
}
return fileId;
}
/**
* ファイルに共有リンクが作成されているか調べ、無い場合はエラーにする
* @param {AuthSettingWrapper} oauth2 OAuth2 認証設定
* @param {String} fileId ファイルの ID
*/
function checkExistingSharedLink(oauth2, fileId) {
const url = `https://api.box.com/2.0/files/${fileId}?fields=shared_link`;
const response = httpClient.begin().authSetting(oauth2).get(url);
const status = response.getStatusCode();
const responseTxt = response.getResponseAsString();
if (status !== 200) {
engine.log(responseTxt);
throw `Failed to get file information. status:${status}`;
}
const jsonRes = JSON.parse(responseTxt);
if (jsonRes.shared_link === null) {
throw `Failed to Delete Shared Link. \n The file(ID:${fileId}) doesn't have a Shared link.`;
}
}
/**
* Delete Shared Link to File on Box 共有リンク削除
* @param {AuthSettingWrapper} oauth2 OAuth2 認証設定
* @param {String} fileId 共有リンクを削除したいファイルのID
*/
function deleteSharedLink(oauth2, fileId) {
const jsonBody = {};
jsonBody["shared_link"] = null;
const url = `https://api.box.com/2.0/files/${fileId}?fields=shared_link`;
const response = httpClient
.begin()
.authSetting(oauth2)
.body(JSON.stringify(jsonBody), "application/json; charset=UTF-8")
.put(url);
const status = response.getStatusCode();
const responseTxt = response.getResponseAsString();
if (status !== 200) {
const error = `Failed to delete. status:${status}`;
engine.log(responseTxt);
throw error;
}
engine.log(`status: ${status} Shared Link was deleted, file ID: ${fileId}`);
}


