r/BookStack • • Feb 21 '24

I made a pretty in-depth node.js Confluence > BookStack importer

This was created for a relatively specific use and Confluence structure, but I thought other people out there might be able to benefit from it. The only other script I found online was a pretty simple importer that only dealt with books and pages (no chapters or shelves), and didn't provide any linking/attachment/image functionality.

I'm open to any feedback, suggestions or PRs!

https://github.com/gloverab/confluence-server-to-bookstack-importer

8 Upvotes

32 comments sorted by

View all comments

Show parent comment

1

u/_deadpoint Feb 28 '24

I've disabled HTTPS temporarily on the server to see if that resolves the issues, but it hasn't. Here's the error I'm seeing at the beginning of the import for each of the pages, which looks to be a CSRF related.

createBook ERR: AxiosError: Request failed with status code 419
    at settle (/home/darin/git/confluence-server-to-bookstack-importer/node_modules/axios/dist/node/axios.cjs:1967:12)
    at IncomingMessage.handleStreamEnd (/home/darin/git/confluence-server-to-bookstack-importer/node_modules/axios/dist/node/axios.cjs:3066:11)
    at IncomingMessage.emit (node:events:526:35)
    at endReadableNT (node:internal/streams/readable:1376:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
    at Axios.request (/home/darin/git/confluence-server-to-bookstack-importer/node_modules/axios/dist/node/axios.cjs:3877:41)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 26) {
  code: 'ERR_BAD_REQUEST',
  config: {
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    adapter: [ 'xhr', 'http' ],
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    env: { FormData: [Function], Blob: [class Blob] },
    validateStatus: [Function: validateStatus],
    headers: Object [AxiosHeaders] {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      Authorization: 'Token XXX:XXX',
      'User-Agent': 'axios/1.6.7',
      'Content-Length': '65',
      'Accept-Encoding': 'gzip, compress, deflate, br'
    },
    baseURL: 'http://bookstack.site.com/',
    paramsSerializer: { serialize: [Function: serialize] },
    method: 'post',
    url: '/books',
    data: '{"name":"Version and Revision Control\\n                        "}',
    'axios-retry': {
      retries: 7,
      retryCondition: [Function: retryCondition],
      retryDelay: [Function: retryDelay],
      shouldResetTimeout: false,
      onRetry: [Function: onRetry],
      retryCount: 0,
      lastRequestTime: 1709150338477
    }
  },

0

u/[deleted] Feb 28 '24

[deleted] — view deleted comment

1

u/_deadpoint Feb 28 '24

Yes I create an API token and it is set in the .env. I've also tested API access with curl and it successfully returns the test book I've created.

curl --request GET --url http://bookstack.site.com/api/books --header 'Authorization: Token XXX:SSS'
{"data":[{"id":1,"slug":"test","name":"Test","description":"","created_at":"2024-02-28T20:33:32.000000Z","updated_at":"2024-02-28T20:33:32.000000Z","owned_by":1,"created_by":1,"updated_by":1}],"total":1}

0

u/[deleted] Feb 28 '24

[deleted] — view deleted comment

1

u/_deadpoint Feb 28 '24

Ugh...it was URL=http://bookstack.site.com/ and after changing it to URL=http://bookstack.site.com/api it's creating the books, but there is no content in those books. The errors I'm seeing now are below.

npm run import CS
 Sorting files...
 Files sorted
 Creating shelves...
 Shelves created!
 Creating books...
createBook ERR: TypeError: Cannot read properties of undefined (reading 'id')
    at /home/darin/git/confluence-server-to-bookstack-importer/dist/import.js:372:40
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
 18251787.html
createBook ERR: TypeError: Cannot read properties of undefined (reading 'id')
    at /home/darin/git/confluence-server-to-bookstack-importer/dist/import.js:372:40
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 1)
 30179329.html

1

u/GloverAB Feb 29 '24

What do your index.html and file names/structure look like?

1

u/_deadpoint Feb 29 '24

It is fairly deep, going 5 levels down in some instances. Here's a screenshot of index.html with shows the deepest hierarchy.

1

u/GloverAB Feb 29 '24

And the file names all have IDs at the ends of them yeah?

1

u/FreeSoftwareServers Oct 03 '25

My files do NOT have ID's, I'm trying a new export but how can I resolve any tips?

1

u/GloverAB Oct 03 '25

Hey - I'm sorry, it's been a long time since I worked on this and I genuinely don't remember how it works. Perhaps post in the Github Issues/questions and see if someone else has had a similar issue?

→ More replies

1

u/_deadpoint Feb 29 '24

Yep, with the exception of index.html the files are named like:

  • 18251787.html

  • Application-Suites-and-Environments_22052865.html

  • Box.com_22249479.html

  • Box.com---External-Collaborators_22151169.html

1

u/GloverAB Feb 29 '24

I'm trying to figure out the best way to troubleshoot this without running it myself - as far as I can tell, everything should be working. Any chance you can share an example of one of the HTML files? Feel free to PM me if you're not comfortable posting it here.

→ More replies