枚举库项目 |
通过枚举 Print Portal 库来获取根文件夹 ID 后,可以枚举特定根文件夹中的库项目(文档和子文件夹)。
在浏览器中,键入用于枚举根文件夹的相同 URI,然后添加要列出其内容的根文件夹的 ID,如下所示:
http://localhost/BarTender/api/v1/libraries/[id]
例如,在本教程的枚举库示例中,Librarian 根文件夹的 ID 为 de6940a6-ff73-465b-aaf2-d39504420fa6,因此 URI 将为 http://localhost/BarTender/api/v1/libraries/de6940a6-ff73-465b-aaf2-d39504420fa6。您需要将 de6940a6-ff73-465b-aaf2-d39504420fa6 替换为自己的 Librarian ID。
|
在此示例中,我们是请求 Librarian 根文件夹的项目列表(这是比 Templates 根文件夹小得多的数据集),因此我们附加了 Librarian 根文件夹的 ID。您可以将 Librarian 根文件夹 ID 替换为 Templates 根文件夹 ID,这会返回 Templates 文件夹中所有项目的列表,该列表要大得多。 |
浏览器中的返回页是 JSON 格式的内容,其中枚举了 Librarian 根文件夹项目。在此示例中,有三个对象。在本教程的后续步骤中,我们将打印 TLC39 Laser_53_rf.btw。
{
"library":{"id":"de6940a6-ff73-465b-aaf2-d39504420fa6",
"name":"Librarian",
"description":"Files that have been added to Librarian.",
"order":1,
"fileFilter":"*.btw",
"relativePath":"lib://","validVisibleUsers":[]},
"contents":["Document1.btw","BMW.btw","TLC39 Laser_53_rf.btw"]
}
/*-----------------------------------------------------------------------------------
Display files from a root folder
*/
let basePrintPortalURL = "https://example.com/Bartender/";
let route = "libraries/";
let id = "9890beae-db51-4b74-a132-d6430a06a192"
fetch(basePrintPortalURL + route + id)
.then(response => response.json())
.then(result => {
console.log(result);
// The following will display a list of templates available in the specific library
const fileList = result.contents;
fileList.forEach(template => console.log(template));
// Displays the name of the library
console.log(result.name);
// Displays the specific error message in case of a failed request
console.log(result.errors.id);
// Displays the title of the error message
console.log(result.title);
// Displays the error message status code
console.log(result.status);
})
.catch(error => {
console.error('There has been a problem with your fetch operation: ', error.message);
});