Token Refresh
Built-in Auto-Refresh
Section titled “Built-in Auto-Refresh”All API functions (library, wishlist, catalog, verify) automatically refresh credentials before each call when the access token is expired or about to expire. You don’t need to call refresh() manually in normal usage.
The returned credentials object always contains the latest tokens — persist it after each call to avoid unnecessary refreshes.
import { library } from 'audible-api-ts'
// No need to check expiration or call refresh() — it's automaticconst { items, credentials: updatedCredentials } = await library(credentials)
// Persist the updated credentials (they may contain a refreshed token)saveCredentialsToStorage(updatedCredentials)Manual Refresh
Section titled “Manual Refresh”If you need explicit control over token refresh (e.g., to refresh on a schedule without making an API call), you can still use refresh() directly:
import { refresh } from 'audible-api-ts'
const updatedCredentials = await refresh(credentials)
// The updated credentials have a new accessToken and expiresAtconsole.log('New expiration:', updatedCredentials.expiresAt)The refreshToken is long-lived and doesn’t expire in normal use.
What Gets Refreshed
Section titled “What Gets Refreshed”| Field | Changes? |
|---|---|
accessToken | Yes — new token |
expiresAt | Yes — new expiration |
refreshToken | No |
adpToken | No |
devicePrivateKey | No |
serial | No |
locale | No |