SDK Node.js
tomba è il client Node.js ufficiale per l'API Tomba. Ogni area dell'API è una classe di servizio, e ogni metodo restituisce una promise per una richiesta.
Requisiti
- Node.js.
package.jsonnon dichiara una versione minima; l'SDK è compilato e testato su Node.js 20. axios, installato come dipendenza.
Installa
Code
Il pacchetto è CommonJS con dichiarazioni TypeScript. Gli esempi di questa pagina sono moduli ES: salvali come file .mjs, o imposta "type": "module" nel tuo package.json.
Autenticati
Crea una chiave API e copia il tuo secret nella pagina API keys, poi esportali entrambi:
Code
L'SDK non legge le variabili d'ambiente. Passa i valori a setKey() e setSecret(), e il client li invia come header X-Tomba-Key e X-Tomba-Secret. La scadenza e la rotazione delle chiavi sono trattate in Autenticazione.
Prima richiesta
Trova l'indirizzo email di una persona in un'azienda:
Code
Ogni metodo si risolve in { data, rateLimit }, dove data è il corpo JSON decodificato. L'API racchiude il payload in un proprio oggetto data (Formato della risposta), quindi l'indirizzo si trova in result.data.data.email. Le dichiarazioni TypeScript tipizzano result.data come il payload stesso, quindi il codice TypeScript ha bisogno di un cast per leggere result.data.data.
Errori
I metodi rifiutano la promise con TombaException, una sottoclasse di Error, quando l'API risponde con uno stato 400 o superiore e, prima di inviare una richiesta, quando manca un argomento obbligatorio.
| Proprietà | Valore |
|---|---|
message | L'errors.message dell'API. |
code | L'oggetto risposta di axios: code.status è lo stato HTTP e code.headers contiene gli header della risposta. undefined quando non è stata ricevuta alcuna risposta. |
response | Il corpo dell'errore decodificato, { errors: { type, message, code } }. |
Code
Enrichment.person(), company() e combined() non rifiutano la promise quando non trovano nulla: questi endpoint rispondono con stato 200 e un corpo errors, quindi controlla result.data.errors. Ogni errors.type è descritto in Errori.
Limiti di frequenza e nuovi tentativi
L'SDK non riprova le richieste. result.rateLimit contiene gli header dei limiti di frequenza della risposta come secondLimit, minuteLimit, dailyLimit, minuteRemaining, dailyRemaining, minuteReset, dailyReset, retryAfter, policy e rateLimit. Gli header numerici vengono convertiti in interi, e un header assente o pari a 0 diventa null.
Un 429 rifiuta la promise con TombaException; leggi il tempo di attesa da error.code.headers["retry-after"] e riprova come descritto in Gestisci le risposte 429.
Le richieste vanno in timeout dopo 120 secondi. Modifica il timeout con client.setTimeout(milliseconds).
Riferimento dei metodi
Crea ogni servizio con il client, ad esempio new Finder(client). Ogni classe è un export con nome di tomba.
| Metodo | Endpoint |
|---|---|
Account.getAccount() | GET /me |
Usage.getUsage() | GET /usage |
Logs.getLogs({ page, limit }) | GET /logs |
Domain.domainSearch({ domain, company, page, limit, country, department, enrich_mobile, webhook_url }) | GET /domain-search |
Finder.emailFinder({ domain, company, firstName, lastName, fullName, enrichMobile, webhook_url }) | GET /email-finder |
Finder.authorFinder(url, webhook_url) | GET /author-finder |
Finder.linkedinFinder(url, enrich_mobile, full, webhook_url) | GET /linkedin |
Finder.emailEnrichment(email, enrich_mobile, webhook_url) | GET /enrich |
Format.emailFormat(domain) | GET /email-format |
Location.getLocation(domain) | GET /location |
Count.emailCount(domain) | GET /email-count |
Verifier.emailVerifier(email, enrich_mobile, webhook_url) | GET /email-verifier |
Sources.emailSources(email) | GET /email-sources |
Enrichment.person(email) | GET /people/find |
Enrichment.company(domain) | GET /companies/find |
Enrichment.combined(email) | GET /combined/find |
Phone.finder({ email, domain, linkedin, full, webhook_url }) | GET /phone-finder |
Phone.validator(phone, country_code) | GET /phone-validator |
Status.domainStatus(domain) | GET /domain-status |
Status.autoComplete(query) | GET /domain-suggestions |
Similar.websites(domain) | GET /similar |
Technology.list(domain) | GET /technology |
Reveal.companiesSearch({ query, filters, page }) | POST /reveal/search |
Flag.listFlags({ page, limit }) | GET /flag |
Flag.createFlag({ flag_type, value, reason, comment }) | POST /flag |
Keys.getKeys() | GET /keys |
Keys.getKey(id) | GET /keys/{id} |
Keys.createKey() | POST /keys |
Keys.resetKey(id) | PUT /keys/{id} |
Keys.deleteKey(id) | DELETE /keys/{id} |
Leads.listLeads({ page, limit, domain }) | GET /leads |
Leads.getLead(id) | GET /leads/{id} |
Leads.createLead(data) | POST /leads |
Leads.updateLead(id, data) | PUT /leads/{id} |
Leads.deleteLead(id) | DELETE /leads/{id} |
LeadsLists.getLists() | GET /leads_lists |
LeadsLists.getList(id) | GET /leads_lists/{id} |
LeadsLists.createList({ name }) | POST /leads_lists |
LeadsLists.updateList(id, { name }) | PUT /leads_lists/{id} |
LeadsLists.deleteList(id) | DELETE /leads_lists/{id} |
LeadsAttributes.getLeadAttributes() | GET /attributes |
LeadsAttributes.getLeadAttribute(id) | GET /attributes/{id} |
LeadsAttributes.createLeadAttribute({ name, type }) | POST /attributes |
LeadsAttributes.updateLeadAttribute(id, { name, type }) | PUT /attributes/{id} |
LeadsAttributes.deleteLeadAttribute(id) | DELETE /attributes/{id} |
Bulk.list(type, { page, limit }) | GET /bulk/{type} |
Bulk.create(type, data) | POST /bulk/{type} |
Bulk.get(type, id) | GET /bulk/{type}/{id} |
Bulk.launch(type, id) | PUT /bulk/{type}/{id} |
Bulk.progress(type, id) | GET /bulk/{type}/{id}/progress |
Bulk.download(type, id) | GET /bulk/{type}/{id}/download |
Bulk.rename(type, id, name) | PUT /bulk/{type}/{id}/rename |
Bulk.archive(type, id) | DELETE /bulk/{type}/{id}/archive |
Bulk.delete(type, id) | DELETE /bulk/{type}/{id}/delete |
type è il segmento {type} elencato in Tipi di job in blocco; l'ordine delle chiamate è descritto in Ciclo di vita. Bulk.create() invia un corpo JSON, quindi non può creare job che richiedono il caricamento di un file CSV, come i job Email Finder. Bulk.download() restituisce il file dei risultati, un CSV, come stringa in result.data.
Codice sorgente
github.com/tomba-io/node (Apache-2.0). Le note di rilascio sono in CHANGELOG.md.