3 This script will scan through all pages, chapters books and shelves via the API to generate a big tree structure list in plaintext.
5 **This is a very simplistic single-script-file example of using the endpoints API together**
6 , it is not a fully-featured & validated script, it error handling is very limited.
8 Keep in mind, The tree generated will reflect content visible to the API user used when running the script.
10 This script follows a `((Shelves > Books > (Chapters > Pages | Pages)) | Books)` structure so books and their contents may be repeated if on multiple shelves. Books not on any shelves will be shown at the end.
14 You will need php (~8.1+) installed on the machine you want to run this script on.
15 You will also need BookStack API credentials (TOKEN_ID & TOKEN_SECRET) at the ready.
20 # Downloading the script
21 # ALTERNATIVELY: Clone the project from GitHub and run locally.
22 curl https://raw.githubusercontent.com/BookStackApp/api-scripts/main/php-generate-tree/generate-tree.php > generate-tree.php
25 # ALTERNATIVELY: Open the script and edit the variables at the top.
26 export BS_URL=https://bookstack.example.com # Set to be your BookStack base URL
27 export BS_TOKEN_ID=abc123 # Set to be your API token_id
28 export BS_TOKEN_SECRET=123abc # Set to be your API token_secret
37 # Generate out the tree to the command line
40 # Generate & redirect output to a file
41 php generate-tree.php > bookstack-tree.txt
43 # Generate with the output shown on the command line and write to a file
44 php generate-tree.php | tee bookstack-tree.txt
47 An example of the output can be seen in the [example.txt](./example.txt) file within the directory of this readme.