PHP SDK
tomba-io/php 是 Tomba API 的官方 PHP 客户端。每个 API 功能区对应一个服务类,每个方法发送 1 个请求。
要求
- PHP 8.1 或更高版本,如
composer.json中所声明。 curl和json扩展。
安装
Code
类从 Tomba 命名空间自动加载;服务类位于 Tomba\Services 中。
认证
在 API keys 页面创建 API 密钥并复制您的 Secret,然后将它们都导出:
Code
SDK 不会读取环境变量。将这些值传给 setKey() 和 setSecret(),客户端会将它们作为 X-Tomba-Key 和 X-Tomba-Secret 请求头发送。有关密钥过期和轮换,请参阅认证。
首个请求
查找某家公司中某个人的邮箱地址:
Code
每个方法都返回一个包含 2 个键的数组:data(解码后的 JSON 响应体)和 rate_limit。API 会将有效负载包装在它自己的 data 对象中(响应格式),因此邮箱地址位于 $result['data']['data']['email']。
错误
当 API 返回 400 或更高的状态码时、cURL 失败时,以及在发送请求之前发现必填参数为空时,SDK 都会抛出 Tomba\TombaException。
| 方法 | 值 |
|---|---|
getCode() | HTTP 状态码。如果错误发生在收到响应之前,则为 0。 |
getMessage() | API 的 errors.message,或 cURL 错误。 |
getResponse() | 解码后的错误响应体 ['errors' => ['type' => …, 'message' => …, 'code' => …]],或 null。 |
Code
Enrichment::person()、company() 和 combined() 在未找到结果时不会抛出异常:这些端点会返回状态码 200 和一个 errors 响应体,因此需检查 $result['data']['errors']。每个 errors.type 的说明请参阅错误。
速率限制和重试
SDK 不会重试。$result['rate_limit'] 保存响应的速率限制响应头,以标头名称为键: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 和 ratelimit。数值为整数,缺失的响应头为 null。
收到 429 时会抛出代码为 429 的 TombaException,但不包含响应头。按照处理 429 响应中的说明,等待一段时间后再重试。
请求在 120 秒后超时;超时时间不可配置。
方法参考
使用客户端创建各个服务,例如 new Finder($client)。
| 方法 | 端点 |
|---|---|
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 是批量类型中列出的 {type} 路径段;调用顺序请参阅生命周期。createBulk() 发送 JSON 请求体,因此无法创建需要上传 CSV 的任务,例如邮箱查找器任务。downloadBulk() 以字符串形式在 $result['data'] 中返回结果文件(一个 CSV)。
源代码
github.com/tomba-io/php(Apache-2.0)。版本说明见 CHANGELOG.md。