
Box: フォルダ共有リンク削除
Box: Delete Shared Link of Folder
この工程は、Box 上の指定フォルダの共有リンク URL を削除します。共有リンクが無い場合は、エラーとなります。
Basic Configs
- 工程名
- メモ
Configs for this Auto Step
- OAuth2
- C1: OAuth2 設定 *
- conf_FolderId
- C2: 共有リンクを削除するフォルダの ID *
Notes
- フォルダ ID は、URL に含まれています。https://{sub-domain}.app.box.com/folder/(Folder ID)
- Box のリフレッシュトークンには、期限があります。期限を超えないよう、定期的に利用する必要があります。(Box: トークンおよびURLの有効期限)
- 共有リンクが無い場合は、エラーとなります。
Capture
See also
Script (click to open)
- 次のスクリプトが記述されている XML ファイルをダウンロードできます
- box-folder-link-delete.xml (C) Questetra, Inc. (MIT License)
- Professional のワークフロー基盤では、ファイル内容を改変しオリジナルのアドオン自動工程として活用できます
main();
function main() {
const oauth2 = configs.get("OAuth2");
let folderId = decideFolderId();
// フォルダに共有リンクがあるか調べる
const existingUrl = getFolderInformation(oauth2, folderId);
// フォルダに共有リンクが無い場合はエラーにする 共有リンクがある場合は削除する
if (existingUrl === null) {
const error = `Failed to Delete Shared Link. The folder(ID:${folderId}) doesn't have a Shared link.`;
throw error;
}
deleteSharedLink(oauth2, folderId);
}
/**
* フォルダのIDをconfigから読み出して出力する。
* @return {String} folderId フォルダの ID
*/
function decideFolderId() {
let folderId = "";
const folderIdDef = configs.getObject("conf_FolderId");
if (folderIdDef === null) {
folderId = configs.get("conf_FolderId");
} else {
folderId = engine.findData(folderIdDef);
}
if (folderId === "" || folderId === null) {
throw "Folder ID is blank";
}
if (folderId === "0") {
throw "Root folder is not eligible.";
}
return folderId;
}
/**
* Get Folder Information on Box フォルダに共有リンクがあるか調べる
* @param {String} oauth2 認証設定
* @param {String} folderId 調べたいフォルダのID
* @return {Object} jsonRes.shared_link フォルダの共有リンクオブジェクト
*/
function getFolderInformation(oauth2, folderId) {
// レスポンスを簡易版にするため、fields 属性を指定
const url = "https://api.box.com/2.0/folders/" + folderId + "?fields=shared_link";
const response = httpClient.begin()
.authSetting(oauth2)
.get(url);
const status = response.getStatusCode();
const responseTxt = response.getResponseAsString();
if (status !== 200) {
const error = `Failed to get folder information. status: ${status}`;
engine.log(responseTxt);
throw error;
}
const jsonRes = JSON.parse(responseTxt);
return jsonRes.shared_link;
}
/**
* Delete Shared Link to Folder on Box 共有リンク削除
* @param {String} OAuth2 認証設定
* @param {String} folderId 共有リンクを削除したいフォルダのID
*/
function deleteSharedLink(oauth2, folderId) {
let jsonBody = {};
jsonBody["shared_link"] = null;
// レスポンスを簡易版にするため、fields 属性を指定
const url = "https://api.box.com/2.0/folders/" + folderId + "?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, forder ID: ${folderId}`);
}