bookstack-api is a type-safe, idiomatic Go client library for the BookStack (https://www.bookstackapp.com) API. https://www.jakoubek.net/open-source/bookstack-api/
Find a file
Oliver Jakoubek e633fc2764 feat(bookstack-api-1us): write README with quick-start guide
Add comprehensive README with installation, authentication, usage
examples for all services, error handling, and available services table.
2026-01-30 09:56:19 +01:00
.beads feat(bookstack-api-1us): write README with quick-start guide 2026-01-30 09:56:19 +01:00
.gitattributes Add project documentation and beads configuration 2026-01-30 09:38:32 +01:00
.gitignore Set up Go module and project structure 2026-01-30 09:36:58 +01:00
AGENTS.md Add project documentation and beads configuration 2026-01-30 09:38:32 +01:00
attachments.go feat(bookstack-api-5gi): implement Attachments CRUD 2026-01-30 09:55:02 +01:00
attachments_test.go feat(bookstack-api-5gi): implement Attachments CRUD 2026-01-30 09:55:02 +01:00
books.go feat(bookstack-api-m6n): implement pagination iterator with iter.Seq2 2026-01-30 09:51:35 +01:00
books_test.go feat(bookstack-api-9xo): implement BooksService List and Get 2026-01-30 09:49:49 +01:00
bookstack.go feat(bookstack-api-7qx): implement Comments CRUD 2026-01-30 09:55:44 +01:00
bookstack_test.go Add validation and error handling to NewClient 2026-01-30 09:45:35 +01:00
chapters.go feat(bookstack-api-dd0): implement ChaptersService List, Get, ListAll 2026-01-30 09:52:38 +01:00
chapters_test.go feat(bookstack-api-dd0): implement ChaptersService List, Get, ListAll 2026-01-30 09:52:38 +01:00
CLAUDE.md Add project documentation and beads configuration 2026-01-30 09:38:32 +01:00
comments.go feat(bookstack-api-7qx): implement Comments CRUD 2026-01-30 09:55:44 +01:00
comments_test.go feat(bookstack-api-7qx): implement Comments CRUD 2026-01-30 09:55:44 +01:00
errors.go Set up Go module and project structure 2026-01-30 09:36:58 +01:00
errors_test.go feat(bookstack-api-vl3): add unit tests for error types and APIError 2026-01-30 09:48:32 +01:00
go.mod Add project documentation and beads configuration 2026-01-30 09:38:32 +01:00
http.go feat(bookstack-api-jt9): implement pages export (Markdown, PDF) 2026-01-30 09:52:10 +01:00
http_test.go feat(bookstack-api-8ea): implement HTTP helper and request building 2026-01-30 09:48:01 +01:00
iterator.go feat(bookstack-api-m6n): implement pagination iterator with iter.Seq2 2026-01-30 09:51:35 +01:00
iterator_test.go feat(bookstack-api-m6n): implement pagination iterator with iter.Seq2 2026-01-30 09:51:35 +01:00
pages.go feat(bookstack-api-9at): implement Pages Delete 2026-01-30 09:54:09 +01:00
pages_test.go feat(bookstack-api-9at): implement Pages Delete 2026-01-30 09:54:09 +01:00
PRD.md Add project documentation and beads configuration 2026-01-30 09:38:32 +01:00
README.md feat(bookstack-api-1us): write README with quick-start guide 2026-01-30 09:56:19 +01:00
search.go feat(bookstack-api-2x5): implement SearchService 2026-01-30 09:50:44 +01:00
search_test.go feat(bookstack-api-2x5): implement SearchService 2026-01-30 09:50:44 +01:00
shelves.go feat(bookstack-api-42g): implement ShelvesService List, Get, ListAll 2026-01-30 09:53:06 +01:00
shelves_test.go feat(bookstack-api-42g): implement ShelvesService List, Get, ListAll 2026-01-30 09:53:06 +01:00
types.go feat(bookstack-api-7qx): implement Comments CRUD 2026-01-30 09:55:44 +01:00
types_test.go feat(bookstack-api-q8z): add unit tests for data types JSON unmarshaling 2026-01-30 09:49:03 +01:00

bookstack-api

A Go client library for the BookStack REST API. Zero external dependencies.

Installation

go get code.beautifulmachines.dev/jakoubek/bookstack-api

Quick Start

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    bookstack "code.beautifulmachines.dev/jakoubek/bookstack-api"
)

func main() {
    client, err := bookstack.NewClient(bookstack.Config{
        BaseURL:     "https://docs.example.com",
        TokenID:     os.Getenv("BOOKSTACK_TOKEN_ID"),
        TokenSecret: os.Getenv("BOOKSTACK_TOKEN_SECRET"),
    })
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()

    // List all books
    books, err := client.Books.List(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }
    for _, book := range books {
        fmt.Printf("%d: %s\n", book.ID, book.Name)
    }
}

Authentication

BookStack uses token-based authentication. Create an API token in your BookStack user profile under API Tokens.

Set the token ID and secret as environment variables:

export BOOKSTACK_TOKEN_ID="your-token-id"
export BOOKSTACK_TOKEN_SECRET="your-token-secret"

Usage

results, err := client.Search.Search(ctx, "deployment guide", nil)
for _, r := range results {
    fmt.Printf("[%s] %s (score: %.1f)\n", r.Type, r.Name, r.Score)
}

Get a Page

page, err := client.Pages.Get(ctx, 42)
fmt.Println(page.HTML)

Export Page as Markdown

md, err := client.Pages.ExportMarkdown(ctx, 42)
fmt.Println(string(md))

Iterate All Books

Uses Go 1.23+ iterators for memory-efficient pagination:

for book, err := range client.Books.ListAll(ctx) {
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(book.Name)
}

Pagination and Filtering

pages, err := client.Pages.List(ctx, &bookstack.ListOptions{
    Count:  10,
    Offset: 0,
    Sort:   "-updated_at",
    Filter: map[string]string{"book_id": "1"},
})

Create and Update Pages

page, err := client.Pages.Create(ctx, &bookstack.PageCreateRequest{
    BookID:   1,
    Name:     "New Page",
    Markdown: "# Hello\n\nPage content here.",
})

page, err = client.Pages.Update(ctx, page.ID, &bookstack.PageUpdateRequest{
    Markdown: "# Updated\n\nNew content.",
})

Error Handling

page, err := client.Pages.Get(ctx, 999)
if errors.Is(err, bookstack.ErrNotFound) {
    fmt.Println("Page not found")
} else if errors.Is(err, bookstack.ErrUnauthorized) {
    fmt.Println("Invalid credentials")
}

Available Services

Service Operations
Books List, ListAll, Get
Pages List, ListAll, Get, Create, Update, Delete, ExportMarkdown, ExportPDF
Chapters List, ListAll, Get
Shelves List, ListAll, Get
Search Search
Attachments List, Get, Create, Update, Delete
Comments List, Get, Create, Update, Delete

Requirements

  • Go 1.23+
  • BookStack instance with API enabled

License

See LICENSE file.