Enumerating Library Items

After you obtain the root folder ID by enumerating the Print Portal libraries, you can enumerate the library items (documents and subfolders) within a specific root folder.

ClosedTo enumerate library items

The return page in the browser is JSON format content that enumerates Librarian root folder items. In this example, there are three objects. In a subsequent step in this tutorial, we will print 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"]

}

ClosedJavaScript Example

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