Getting Started
Installation
Section titled “Installation”# bunbun add audible-api-ts
# npmnpm install audible-api-ts
# pnpmpnpm add audible-api-tsRequirements
Section titled “Requirements”- Node.js 18+ (for native
fetchandcrypto) - TypeScript 5+ (recommended)
Quick Start
Section titled “Quick Start”The Audible API uses a 3-step authentication flow:
- Generate a login URL — redirect the user to Amazon’s login page
- Register the device — exchange the authorization code for credentials
- 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 marketplaceconst { 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 deviceconst credentials = await register(authorizationCode, session)
// → Store `credentials` securely — you'll reuse them for all API calls
// Step 3: Fetch the user's libraryconst { 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 audiobooksPrimal 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 aventureDune - 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-FictionCatalog Search
Section titled “Catalog Search”Search the Audible catalog by category, sorted by popularity:
// Top 10 Science Fictionconst { 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)Wishlist
Section titled “Wishlist”const { items: wishlist } = await wishlist(credentials)
wishlist.map((book) => console.log(`${book.title} — ${book.durationMinutes} min — ${book.publisher}`))Output:
L'Empire ultime — 1560 min — LizzieThe Lies of Locke Lamora — 1356 min — Orion Publishing GroupEmpire of Silence — 1558 min — Recorded BooksWhat’s Next?
Section titled “What’s Next?”- Authentication Guide — Deep dive into the PKCE flow, cookies, and session management
- Library & Wishlist — All available fields, filtering, stats, and catalog search
- Token Refresh — Handle token expiration gracefully
- Locales — All 10 supported Audible marketplaces
- API Reference — Complete function signatures and parameters
- Types Reference — All exported TypeScript types