枚举库

通过枚举库,可以生成 Print Portal 根文件夹的列表。除了身份验证(如果需要),这是通过自动化打印文档的第一步。

关闭枚举库

浏览器中的返回页是 JSON 格式的内容,其中枚举了根文件夹。所返回的 Librarian 根文件夹“id”将用于后续示例中。

{

"id":"b49be392-c6ec-43e9-a7ad-c8b23f8d3c4c",

"name":"Templates",

"description":"Sample documents included with the BarTender Designer",

"order":0,

"fileFilter":"*.btw",

"relativePath":"Templates",

"validVisibleUsers":[]},

{"id":"de6940a6-ff73-465b-aaf2-d39504420fa6",

"name":"Librarian",

"description":"Files that have been added to Librarian.",

"order":1,

"fileFilter":"*.btw",

"relativePath":"lib://",

"validVisibleUsers":[]

}

关闭JavaScript 示例

复制
//*---------------------------------------------------------------------------------------
 Enumerate files within a given root folder with authentication enabled */

let basePrintPortalURL = "https://example.com/Bartender/";
let route = "libraries/";
let token = "token_value_from_authentication_call";

fetch(basePrintPortalURL + route, {
    method: 'get',
    headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + token
  },
    })
.then(response => response.json())
.then(result => {
  console.log(result);

  // In case of multiple libraries, the following will display each library ID individually
 
    for (const library of result)
    {

    // Displays the libraryID(s), the ID can be used in another request to gather information about an individual library
    console.log(library.id);

    // Displays the name(s) of each library
    console.log(library.name);

    // Displays the relative path of each library
    console.log(library.relativePath);
    }

  // 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);
  });