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.
In the browser, type the same URI that you used for enumerating the root folders, but with the addition of the root folder ID that you want to list the contents of, as follows:
http://localhost/BarTender/api/v1/libraries/[id]
For example, in the enumerating libraries example in this tutorial, the ID for the Librarian root folder was de6940a6-ff73-465b-aaf2-d39504420fa6, so the URI would be http://localhost/BarTender/api/v1/libraries/de6940a6-ff73-465b-aaf2-d39504420fa6. You will need to replace de6940a6-ff73-465b-aaf2-d39504420fa6 with your own Librarian ID.
|
In this example, we are requesting a list of items for the Librarian root folder, which is a much smaller data set than the Templates root folder, and therefore we append the ID for the Librarian root folder. You could replace the Librarian root folder ID with the Templates root folder ID, and this would return a much larger list of all the items within the Templates folder. |
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"]
}
/*-----------------------------------------------------------------------------------
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);
});