1 # We receive the book ID as an argument from when the script is ran.
2 # This will be the ID of the book we're uploaded pages into.
4 [Parameter(Mandatory=$true)]
8 # BookStack API variables
9 # Uses values from the environment otherwise could be hardcoded here
10 $baseUrl = $env:BS_URL
11 $tokenId = $env:BS_TOKEN_ID
12 $tokenSecret = $env:BS_TOKEN_SECRET
14 # Function to create a page in BookStack
15 function Create-BookstackPage {
17 [Parameter(Mandatory=$true)]
20 [Parameter(Mandatory=$true)]
23 [Parameter(Mandatory=$true)]
27 # Create the data to send to the API
34 # Ready the HTTP headers, including our auth header
35 $authHeader = "Token {0}:{1}" -f $tokenId, $tokenSecret
37 "Content-Type" = "application/json"
38 "Authorization" = $authHeader
41 # Send the request to our API endpoint as a POST request
42 $url = "{0}/api/pages" -f $baseUrl
43 Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $body
46 # Get the html files in the relative "./files" directory
47 $files = Get-ChildItem -Path ".\files" -Filter "*.html" -File
49 # For each of our HTML files, get the file data and name
50 # then create a page with name matching the filename
51 # and HTML content using the contents of the file.
52 foreach ($file in $files) {
53 $fileContent = Get-Content -Path $file.FullName
54 Create-BookStackPage $file.Name $fileContent $parentBookId