SDK npm — whatsapp-data-sdk

Client ufficiale TypeScript/JavaScript per l'API dati di WhatsApp. Metodi tipizzati, nessuna dipendenza a runtime, ricerche con priorità nella cache e una tassonomia degli errori chiara.

Dipendenze zero
Completamente digitato
ESM + CJS
npmGitHub

Installare

npm install whatsapp-data-sdk
# or
pnpm add whatsapp-data-sdk
# or
yarn add whatsapp-data-sdk

Utilizza la funzione fetch nativa: funziona con Node 18+, Bun, Deno e browser. Non richiede axios né polyfill.

Avvio rapido

import { WhatsAppDataClient } from 'whatsapp-data-sdk'

const client = new WhatsAppDataClient({
  apiKey: process.env.WA_API_KEY!, // sent as x-rapidapi-key
})

const profile = await client.getProfile('59898297150')
console.log(profile.exists, profile.about, profile.profilePic)

Autenticazione e trasporto

La tua chiave API viene sempre inviata nell'intestazione x-rapidapi-key. Scegli la destinazione delle richieste tramite il trasporto.

transportConduttore dal vivoHost solo cache/DBNote
'proxy' (predefinito)whatsapp-proxy.checkleaked.cc/number_cache sullo stesso hostSemplice: un unico URL di base, senza intestazione host.
'rapidapi'wp-data.p.rapidapi.comwp-data-db-only.p.rapidapi.comImposta automaticamente x-rapidapi-host. Utilizza la tua chiave RapidAPI.
// RapidAPI marketplace (live + DB-only hosts)
const client = new WhatsAppDataClient({
  apiKey: process.env.RAPIDAPI_KEY!,
  transport: 'rapidapi',
})

È possibile sovrascrivere qualsiasi URL/host tramite baseUrl, cacheBaseUrl, rapidApiHost, rapidApiCacheHost.

Ricerche con priorità alla cache (risparmio di denaro)

La funzione checkCached() legge prima l'endpoint economico della cache/solo database e, solo se il numero non è ancora presente nella cache, ricorre a un controllo live a pagamento.

// cacheFirst (default): DB first → live only on a miss
const r1 = await client.checkCached('59898297150')
console.log(r1._source) // 'cache' | 'live'

// cacheOnly: never spend on a live check
const r2 = await client.checkCached('59898297150', { mode: 'cacheOnly' })

// live: always fresh
const r3 = await client.checkCached('59898297150', { mode: 'live' })

Sul trasporto rapidapi, questo instrada la lettura della cache a wp-data-db-only.p.rapidapi.com e il fallback live a wp-data.p.rapidapi.com: un flusso a due host che consente di risparmiare denaro.

Riferimento API

Ogni metodo corrisponde in modo univoco a un endpoint del marketplace.

Profilo e immagini

await client.getProfile(number, options?)            // Get Profile Information
await client.getProfileNoPicture(number, options?)   // Get Profile Information (No profile pic)
await client.getLastPicture(number)                  // Get Last Saved Picture (JPEG bytes)
await client.getDeviceCount(number)                  // Device count
await client.getOsintInfo(number)                    // OSINT Info

Le opzioni di getProfile includono telegram, google, lookup, includeCarrier, base64, geminiFaceAnalysis, reverseImageSearch, fullAiReport, includeDeviceCount, onlyCheck, useCache, forceBypassCache e altro ancora.

const pic = await client.getLastPicture('59898297150')
// pic.bytes: Uint8Array, pic.contentType: string
htmlImg.src = pic.toDataUri()

Violazioni telefoniche

await client.getPhoneBreaches(number, { limit, offset }) // Get Phone Breaches (no external key)
await client.getPhoneBreachesExternal(number, apiKey)     // Get Phone Breaches (your checkleaked.cc key)

Ricerca e database

await client.search({ countryCode: 'UY', isBusiness: true, limit: 20 })   // Search
await client.searchGoogleMaps({ latitude: -34.9, longitude: -56.16, radius: 2000 }) // Search in Google Maps

// Bulk downloads return a Google Drive link to the full dataset (MEGA tier only)
const leaks = await client.getLeakedNumbersInfo()   // Leaked Numbers (500M database)
console.log(leaks.driveFolder.url)

const backup = await client.downloadEntireDatabase() // Download the Entire DB
console.log(backup.driveFolder.url)

Assegni cumulativi

await client.bulkCheck(numbers, { includeBusiness, noBanStatus }) // Bulk Check (live, max 50)
await client.bulkCheckDbBasic(numbers)                            // Basic Check (DB, max 1000)
await client.bulkCheckDbFull(numbers)                            // Full Check (DB, max 1000)

Telegramma e vettore

// Telegram (experimental)
await client.getTelegramProfile('59898297150')            // single
await client.getTelegramProfile(['num1', 'num2'])         // batch

// Carrier
await client.carrierLookup(number)              // Carrier Lookup
await client.carrierLookupAlt(number)           // Carrier Lookup Alternative (spam-report signals)
await client.carrierLookupAlt(number, { page: 2 }) // page through the reports (response has a `pagination` block)

"Non trovato" si risolve — non genera

Il fatto che un numero non sia presente su WhatsApp è un risultato normale, non un errore, quindi questi vengono risolti (non vengono mai rifiutati):

getProfile / getProfileNoPicture / checkCached restituisce una voce con exists:false (e codice:'NUMBER_NOT_FOUND').
La ricerca con zero risultati restituisce una pagina vuota (successo:false, data.docs:[]).
La funzione getDeviceCount per un numero non WhatsApp restituisce successo:false (in assenza di deviceCount).
const p = await client.getProfile('14155552671')
if (!p.exists) console.log('not on WhatsApp')

Quali sono gli errori che vengono generati: un numero non valido (400), errore di autenticazione (401/403), limite di frequenza (429), timeout, errore di rete e 5xx.

Errori

Tutti i rifiuti sono una sottoclasse di WhatsAppDataError, quindi un singolo blocco catch gestisce tutto.

ClasseQuando
ValidationErrorArgomenti non validi (generati in modo sincrono, prima di qualsiasi richiesta; senza .status).
AuthError401 / 403 — chiave mancante, non valida o annullata.
RateLimitError429 — contiene retryAfterMs quando il server ha inviato Retry-After.
HttpErrorQualsiasi altro numero diverso da 2xx (ad esempio 400, 5xx); contiene .status e .body.
TimeoutErrorLa richiesta ha superato il tempo limite.
NetworkErrorErrore di trasporto (DNS, ripristino della connessione, interruzione a metà del processo).
WhatsAppDataErrorClasse base per tutto quanto sopra.
import { AuthError, RateLimitError, TimeoutError, WhatsAppDataError } from 'whatsapp-data-sdk'

try {
  await client.getProfile('59898297150')
} catch (err) {
  if (err instanceof AuthError) {/* 401/403 — bad/unsubscribed key */}
  else if (err instanceof RateLimitError) {/* 429 — err.retryAfterMs */}
  else if (err instanceof TimeoutError) {/* request timed out */}
  else if (err instanceof WhatsAppDataError) {
    console.error(err.status, err.body)
  }
}

Configurazione

new WhatsAppDataClient({
  apiKey: '...',           // required
  transport: 'proxy',      // 'proxy' | 'rapidapi'
  timeoutMs: 60000,        // request timeout (bounds headers AND body read)
  retries: 2,              // retry 5xx / 429 / network / timeout (GET only) with backoff
  retryDelayMs: 500,       // exponential base; 429 honors Retry-After when longer
  baseUrl: '...',          // override live base URL
  cacheBaseUrl: '...',     // override cache/DB-only base URL
  rapidApiHost: '...',     // override live x-rapidapi-host
  rapidApiCacheHost: '...',// override cache x-rapidapi-host
  userAgent: '...',        // custom User-Agent
  fetch: globalThis.fetch, // inject a custom fetch (tests / polyfills)
})

Formati dei numeri di telefono

È possibile passare i numeri in qualsiasi formato: l'SDK li normalizza ed esporta le funzioni di supporto in modo da poter riutilizzare la stessa normalizzazione.

import { toDigits, toE164 } from 'whatsapp-data-sdk'
toDigits('+598 98 297 150') // '59898297150'  (path & live endpoints)
toE164('59898297150')       // '+59898297150' (bulk-DB endpoints; their validator requires it)
// both throw ValidationError on input with no digits

Opzioni per richiesta

Ogni metodo accetta un oggetto di opzioni finale che accetta anche segnale, timeoutMs e tentativi — per la cancellazione e la regolazione per ogni chiamata:

const controller = new AbortController()
const p = client.getProfile('59898297150', {
  telegram: true,
  signal: controller.signal, // cancel this specific request
  timeoutMs: 5000,           // override the client timeout for this call
})
controller.abort() // rejects with WhatsAppDataError

Imparentato

Cosa Dicono i Nostri Utenti

Recensioni reali dai nostri clienti soddisfatti

4.5/5 (176 recensioni)