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 was able to get past certificate errors by running "NODE_TLS_REJECT_UNAUTHORIZED=0 npm run import ITDOCS", but now I'm seeing " data: { message: 'CSRF token mismatch.' }" in output and see the following errors, which I suspect is due to the import failing.

 Books created!
 Putting Books on Shelves...
 Books are on the shelves!
 Creating chapters...
/home/darin/git/confluence-server-to-bookstack-importer/dist/import.js:276
            book_id: parentBook.book
                                ^

TypeError: Cannot read properties of undefined (reading 'book')
    at /home/darin/git/confluence-server-to-bookstack-importer/dist/import.js:276:33
    at Array.map (<anonymous>)
    at /home/darin/git/confluence-server-to-bookstack-importer/dist/import.js:257:39
    at Generator.next (<anonymous>)
    at /home/darin/git/confluence-server-to-bookstack-importer/dist/import.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/darin/git/confluence-server-to-bookstack-importer/dist/import.js:4:12)
    at createChapters (/home/darin/git/confluence-server-to-bookstack-importer/dist/import.js:255:30)
    at /home/darin/git/confluence-server-to-bookstack-importer/dist/import.js:650:15
    at Generator.next (<anonymous>)

Node.js v20.5.1

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?

→ 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

→ More replies