SDK para PHP
tomba-io/php é o cliente oficial em PHP para a API da Tomba. Cada área da API é uma classe de serviço, e cada método envia uma requisição.
Requisitos
- PHP 8.1 ou posterior, conforme declarado em
composer.json. - As extensões
curlejson.
Instalação
Code
As classes são carregadas automaticamente a partir do namespace Tomba; os serviços estão em Tomba\Services.
Autenticação
Crie uma chave de API e copie seu secret na página API keys e depois exporte os dois:
Code
O SDK não lê variáveis de ambiente. Passe os valores para setKey() e setSecret(), e o cliente os envia nos cabeçalhos X-Tomba-Key e X-Tomba-Secret. A expiração e a rotação das chaves são explicadas em Autenticação.
Primeira requisição
Encontre o endereço de email de uma pessoa em uma empresa:
Code
Todos os métodos retornam um array com duas chaves: data, o corpo JSON decodificado, e rate_limit. A API encapsula o payload no seu próprio objeto data (Formato da resposta), então o endereço fica em $result['data']['data']['email'].
Erros
O SDK lança Tomba\TombaException quando a API responde com status 400 ou superior, quando o cURL falha e, antes de enviar uma requisição, quando um argumento obrigatório está vazio.
| Método | Valor |
|---|---|
getCode() | O status HTTP. 0 quando o erro aconteceu antes de uma resposta ser recebida. |
getMessage() | O errors.message da API, ou o erro do cURL. |
getResponse() | O corpo do erro decodificado, ['errors' => ['type' => …, 'message' => …, 'code' => …]], ou null. |
Code
Enrichment::person(), company() e combined() não lançam exceções quando nada é encontrado: esses endpoints respondem com o status 200 e um corpo errors, então verifique $result['data']['errors']. Cada errors.type é descrito em Erros.
Limites de requisições e novas tentativas
O SDK não faz novas tentativas. $result['rate_limit'] contém os cabeçalhos de limite de requisições da resposta, com o nome do cabeçalho como chave: 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. Os números são inteiros, e um cabeçalho ausente é null.
Um 429 lança TombaException com o código 429, sem os cabeçalhos da resposta. Aguarde antes de tentar novamente, conforme descrito em Tratar respostas 429.
As requisições expiram após 120 segundos; o tempo limite não é configurável.
Referência de métodos
Crie cada serviço com o cliente, por exemplo new Finder($client).
| Método | 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 é o segmento {type} listado em Tipos de jobs em massa; a ordem das chamadas é descrita em Ciclo de vida. createBulk() envia um corpo JSON, então não pode criar jobs que exigem o envio de um CSV, como os jobs de Email Finder. downloadBulk() retorna o arquivo de resultados, um CSV, como string em $result['data'].
Código-fonte
github.com/tomba-io/php (Apache-2.0). As notas de versão estão em CHANGELOG.md.