SDK PHP
tomba-io/php è il client PHP ufficiale per l'API Tomba. Ogni area dell'API è una classe di servizio, e ogni metodo invia una richiesta.
Requisiti
- PHP 8.1 o successivo, come dichiarato in
composer.json. - Le estensioni
curlejson.
Installa
Code
Le classi vengono caricate automaticamente dal namespace Tomba; i servizi si trovano in Tomba\Services.
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 restituisce un array con due chiavi: data, il corpo JSON decodificato, e rate_limit. L'API racchiude il payload in un proprio oggetto data (Formato della risposta), quindi l'indirizzo si trova in $result['data']['data']['email'].
Errori
L'SDK lancia Tomba\TombaException quando l'API risponde con uno stato 400 o superiore, quando cURL non riesce e, prima di inviare una richiesta, quando un argomento obbligatorio è vuoto.
| Metodo | Valore |
|---|---|
getCode() | Lo stato HTTP. 0 quando l'errore si è verificato prima della ricezione di una risposta. |
getMessage() | L'errors.message dell'API, o l'errore di cURL. |
getResponse() | Il corpo dell'errore decodificato, ['errors' => ['type' => …, 'message' => …, 'code' => …]], o null. |
Code
Enrichment::person(), company() e combined() non lanciano eccezioni 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['rate_limit'] contiene gli header dei limiti di frequenza della risposta, indicizzati per nome dell'header: x-second-rate-limit, x-minute-rate-limit, x-daily-rate-limit, x-minute-request-left, x-daily-request-left, x-minute-reset-seconds, x-daily-reset-seconds, retry-after, ratelimit-policy e ratelimit. I numeri sono interi, e un header assente è null.
Un 429 lancia TombaException con codice 429, senza gli header della risposta. Attendi prima di riprovare, come descritto in Gestisci le risposte 429.
Le richieste vanno in timeout dopo 120 secondi; il timeout non è configurabile.
Riferimento dei metodi
Crea ogni servizio con il client, ad esempio new Finder($client).
| Metodo | Endpoint |
|---|---|
Account::getAccount() | GET /me |
Usage::getUsage() | GET /usage |
Logs::getLogs(?int $page = null, ?int $limit = null) | GET /logs |
Domain::domainSearch(string $domain, int $page = null, int $limit = null, string $department = null, bool $enrichMobile = null, string $webhookUrl = null) | GET /domain-search |
Finder::emailFinder(string $domain, string $firstName, string $lastName, string $webhookUrl = null) | GET /email-finder |
Finder::authorFinder(string $url, string $webhookUrl = null) | GET /author-finder |
Finder::linkedinFinder(string $url, string $webhookUrl = null) | GET /linkedin |
Format::emailFormat(string $domain) | GET /email-format |
Location::getLocation(string $domain) | GET /location |
Count::emailCount(string $domain) | GET /email-count |
Verifier::emailVerifier(string $email, string $webhookUrl = null) | GET /email-verifier |
Sources::emailSources(string $email) | GET /email-sources |
Enrichment::person(string $email, string $webhookUrl = null) | GET /people/find |
Enrichment::company(string $domain) | GET /companies/find |
Enrichment::combined(string $email) | GET /combined/find |
Finder::phoneFinder(string $email, string $webhookUrl = null) | GET /phone-finder |
Phone::phoneFinder(array $params, string $webhookUrl = null) | GET /phone-finder |
Phone::phoneValidator(string $phone, ?string $countryCode = null) | GET /phone-validator |
Status::domainStatus(string $domain) | GET /domain-status |
Status::autoComplete(string $query) | GET /domain-suggestions |
Similar::websites(string $domain) | GET /similar |
Technology::list(string $domain) | GET /technology |
Reveal::companiesSearch(array $params) | POST /reveal/search |
Flag::listFlags(?int $page = null, ?int $limit = null) | GET /flag |
Keys::getKeys() | GET /keys |
Keys::getKey(string $id) | GET /keys/{id} |
Keys::createKey() | POST /keys |
Keys::resetKey(string $id) | PUT /keys/{id} |
Keys::deleteKey(string $id) | DELETE /keys/{id} |
Leads::listLeads(?int $page = null, ?int $limit = null, ?string $domain = null) | GET /leads |
Leads::getLead(string $id) | GET /leads/{id} |
Leads::createLead(array $data) | POST /leads |
Leads::updateLead(string $id, array $data) | PUT /leads/{id} |
Leads::deleteLead(string $id) | DELETE /leads/{id} |
LeadsLists::getLists() | GET /leads_lists |
LeadsLists::deleteListId(string $id) | DELETE /leads_lists/{id} |
LeadsAttributes::getLeadAttributes() | GET /attributes |
LeadsAttributes::deleteLeadAttribute(string $id) | DELETE /attributes/{id} |
Bulk::listBulks(string $type, ?array $params = null) | GET /bulk/{type} |
Bulk::createBulk(string $type, array $data) | POST /bulk/{type} |
Bulk::getBulk(string $type, int $id) | GET /bulk/{type}/{id} |
Bulk::launchBulk(string $type, int $id) | PUT /bulk/{type}/{id} |
Bulk::bulkProgress(string $type, int $id) | GET /bulk/{type}/{id}/progress |
Bulk::downloadBulk(string $type, int $id) | GET /bulk/{type}/{id}/download |
Bulk::renameBulk(string $type, int $id, string $name) | PUT /bulk/{type}/{id}/rename |
Bulk::archiveBulk(string $type, int $id) | DELETE /bulk/{type}/{id}/archive |
Bulk::deleteBulk(string $type, int $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. createBulk() invia un corpo JSON, quindi non può creare job che richiedono il caricamento di un file CSV, come i job Email Finder. downloadBulk() restituisce il file dei risultati, un CSV, come stringa in $result['data'].
Codice sorgente
github.com/tomba-io/php (Apache-2.0). Le note di rilascio sono in CHANGELOG.md.