Skip to content

Getting Started

Terminal window
# bun
bun add audible-api-ts
# npm
npm install audible-api-ts
# pnpm
pnpm add audible-api-ts
  • Node.js 18+ (for native fetch and crypto)
  • TypeScript 5+ (recommended)

The Audible API uses a 3-step authentication flow:

  1. Generate a login URL — redirect the user to Amazon’s login page
  2. Register the device — exchange the authorization code for credentials
  3. Fetch data — use credentials to access library, wishlist, and catalog
import {
login,
register,
library,
wishlist,
catalog,
} from 'audible-api-ts'
// Step 1: Generate the login URL for the French marketplace
const { loginUrl, session, cookies } = await login('fr')
// → Redirect your user to `loginUrl`
// → Set `cookies` in the browser before redirecting
// → Store `session` — you'll need it in step 2
// Step 2: After the user logs in, extract the authorization code
// from the callback URL and register the device
const credentials = await register(authorizationCode, session)
// → Store `credentials` securely — you'll reuse them for all API calls
// Step 3: Fetch the user's library
const { items: library } = await library(credentials)
console.log(`Found ${library.length} audiobooks`)
library.map((book) => {
const rating = book.rating?.overallDistribution
const hours = Math.floor(book.durationMinutes / 60)
const mins = book.durationMinutes % 60
console.log(`${book.title}`)
console.log(` Authors: ${book.authors.join(', ')}`)
console.log(` Narrators: ${book.narrators.join(', ')}`)
console.log(` Duration: ${hours}h ${mins}min`)
console.log(` Publisher: ${book.publisher}`)
if (book.series) {
console.log(` Series: ${book.series.name} #${book.series.position}`)
}
if (rating) {
console.log(` Rating: ${rating.averageRating.toFixed(1)}/5 (${rating.numRatings} votes)`)
}
if (book.listeningStatus?.percentComplete) {
console.log(` Progress: ${book.listeningStatus.percentComplete}%`)
}
if (book.listeningStatus?.finishedAt) {
console.log(` Finished: ${book.listeningStatus.finishedAt.toLocaleDateString()}`)
}
if (book.categories.length > 0) {
const genres = book.categories.map((c) => c.categories.map((cat) => cat.name).join(' > '))
console.log(` Genres: ${genres.join(', ')}`)
}
})

Output:

Found 142 audiobooks
Primal Hunter
Authors: Zogarth, Astrid Vallet - traducteur
Narrators: Sébastien Mortamet
Duration: 29h 30min
Publisher: Lizzie
Series: Primal Hunter #4
Rating: 4.8/5 (156 votes)
Progress: 5%
Genres: Science-Fiction et fantasy > Fantasy > Action et aventure
Dune - Livre premier et livre second
Authors: Frank Herbert, Michel Demuth - traducteur
Narrators: Benjamin Jungers
Duration: 18h 0min
Publisher: Lizzie
Rating: 4.7/5 (2830 votes)
Finished: 12/15/2024
Genres: Science-Fiction et fantasy > Science-Fiction

Search the Audible catalog by category, sorted by popularity:

// Top 10 Science Fiction
const { items } = await catalog(credentials, {
category: 'science-fiction', // genre name, resolved per locale
limit: 10, // Relevance is the default sort
})
items.map((book, i) => {
const rating = book.rating?.overallDistribution
console.log(
`${i + 1}. ${book.title}` +
`${rating?.averageRating?.toFixed(1)}/5 (${rating?.numRatings} votes)`
)
})

Output:

1. Project Hail Mary — 4.9/5 (82341 votes)
2. Dune — 4.7/5 (45210 votes)
3. The Hitchhiker's Guide to the Galaxy — 4.6/5 (38102 votes)
const { items: wishlist } = await wishlist(credentials)
wishlist.map((book) =>
console.log(`${book.title}${book.durationMinutes} min — ${book.publisher}`)
)

Output:

L'Empire ultime — 1560 min — Lizzie
The Lies of Locke Lamora — 1356 min — Orion Publishing Group
Empire of Silence — 1558 min — Recorded Books