Home

Export Your Kindle Library

By Joel Dare - Written March 3, 2024

The instructions below will allow you to download a list of books from your Kindle Library.

// Initial setup
let xhr = new XMLHttpRequest()
let domain = 'https://read.amazon.com/'
let items = []
let csvData = ""
let markdownData = ""

// Send an XHR request to retrieve a list of books sorted by acquisition_desc
function getItemsList(paginationToken = null) {
  let url = domain + 'kindle-library/search?query=&libraryType=BOOKS' + ( paginationToken ? '&paginationToken=' + paginationToken : '' ) + '&sortType=acquisition_desc&querySize=50'
  xhr.open('GET', url, false)
  xhr.send()  
}

// Request the page
xhr.onreadystatechange = function() {
  switch ( xhr.readyState ) {
    case 0:
      console.log('uninitialized')
      break
    case 1:
      console.log('loading...')
      break
    case 4:
      if(xhr.status == 200) {
        let data = xhr.responseText
        data = JSON.parse(data)
        if(data.itemsList) {
          items.push(...data.itemsList)
        }
        if(data.paginationToken) {
          getItemsList(data.paginationToken)
        }
      } else {
        console.log('Failed')
      }
      break
  }
}

getItemsList()

// Export to Markdown
items.forEach(item => {
  console.log(item);
  csvData += '"' + item.asin + '","' + item.title + '","' + item.authors[0] + '","' + item.percentageRead + '"\n'
  markdownData += '| ' + item.asin + ' | ' + item.title + ' | ' + item.authors[0] + ' | ' + item.percentageRead + ' |\n'
})

//window.location = 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData)
window.location = 'data:text/markdown;charset=utf8,' + encodeURIComponent(markdownData)

I originally got the following code from usayamadx/ExportKindle.js then modified it slightly to add author and purchase date.

Build your next site in pure HTML and CSS

Want to build your next site in pure HTML and CSS? Join the free Five-Day Neat Starter Email Course and build a lean, production-ready page before Friday.

Email Me the Crash Course


JoelDare.com © Dare Companies Dotcom LLC

Terms - Privacy