
Box: フォルダ検索 (Box: Search Folder)
この工程は、Box の指定フォルダ直下に特定の名前のフォルダがあるかどうか調べます。
Configs:共通設定
- 工程名
- メモ
Configs
- C1: OAuth2 設定 *
- C2: 検索するフォルダの親フォルダの ID (空白の場合ルートフォルダ直下を検索します)#{EL}
- C3: 検索するフォルダの名称 *#{EL}
- C4: フォルダの ID を保存するデータ項目
- C5: フォルダの URL を保存するデータ項目
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-search.xml (C) Questetra, Inc. (MIT License)
- Professional をご利用であればファイルの内容を改変することでオリジナルのアドオンとして活用できます
main();
function main(){
let parentFolderId = configs.get("ParentFolderId");
if (parentFolderId === "" ||parentFolderId === null) {
parentFolderId = "0";
}
const folderName = configs.get("FolderName");
if (folderName === "" ||folderName === null) {
throw "Folder Name is blank";
}
//get C4&C5
const idData = configs.getObject( "FolderIdItem" );
const urlData = configs.getObject( "WebViewUrlItem" );
//If neither C4 nor C5 are set,throw error
if((idData === null || idData === "") && (urlData === null || urlData === "")){
throw "Neither of Data Items to save result are set.";
}
const oauth2 = configs.get("conf_OAuth2");
const {folderId, folderUrl} = searchFolder(oauth2,parentFolderId,folderName);
//set ID to Data Item
if (idData !== null) {
engine.setData(idData,folderId);
}
//set URL to Data Item
if (urlData !== null) {
engine.setData(urlData, folderUrl);
}
}
//search folder on box
function searchFolder(oauth2,parentFolderId,folderName){
const url = `https://api.box.com/2.0/folders/${parentFolderId}/items`;
let marker = "";
const limit = httpClient.getRequestingLimit();
for(let count = 0; count < limit; count++) {
const response = httpClient.begin()
.authSetting(oauth2)
.queryParam("fields", "id,type,name")
.queryParam("limit", "1000")
.queryParam("usemarker","true")
.queryParam("marker",marker)
.get(url);
const status = response.getStatusCode();
const responseTxt = response.getResponseAsString();
engine.log(`status: ${status}`);
if (status >= 300) {
engine.log(responseTxt);
throw "Failed to search";
}
const json = JSON.parse(responseTxt)
const items = json.entries;
for(let i = 0; i < items.length; i++){
if(items[i].type === "folder" && items[i].name === folderName){
const url = `https://app.box.com/folder/${items[i].id}`;
return {
folderId : items[i].id,
folderUrl : url
};
}
}
marker = json.next_marker;
if(marker === undefined || marker === '' || marker === null) {
throw `Folder ${folderName} doesn't exist.`;
}
}
throw "Too many folders and files are in the specified folder";
}