]> BookStack Code Mirror - api-scripts/blob - php-generate-tree/readme.md
Added php-generate-tree script
[api-scripts] / php-generate-tree / readme.md
1 # Generate Tree
2
3 This script will scan through all pages, chapters books and shelves via the API to generate a big tree structure list in plaintext.
4
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.
7
8 Keep in mind, The tree generated will reflect content visible to the API user used when running the script.
9
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.
11
12 ## Requirements
13
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.
16
17 ## Running
18
19 ```bash
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
23
24 # Setup
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
29
30 # Running the script
31 php generate-tree.php
32 ```
33
34 ## Examples
35
36 ```bash
37 # Generate out the tree to the command line
38 php generate-tree.php
39
40 # Generate & redirect output to a file
41 php generate-tree.php > bookstack-tree.txt
42
43 # Generate with the output shown on the command line and write to a file
44 php generate-tree.php | tee bookstack-tree.txt
45 ```
46
47 An example of the output can be seen in the [example.txt](./example.txt) file within the directory of this readme.