# 从 Clearbit Combined API 迁移

本指南将 Clearbit 的 Combined API（`GET https://person.clearbit.com/v2/combined/find`）映射到 Tomba 的 [`GET /v1/combined/find`](/api/enrichment#combined-api)，后者根据邮箱地址返回 Clearbit 风格的人员和公司信息。Clearbit 的行为已于 2026-09-29 对照[最后一版公开的 Clearbit API 参考](https://web.archive.org/web/20240909071651/https://dashboard.clearbit.com/docs)（2024 年 9 月）进行核实。

## 开始之前

- 获取您的 API 密钥（`ta_…`）和 Secret（`ts_…`）；请参阅[认证](/authentication)。
- 在[积分消耗](/usage-and-quotas#credit-costs)中查看一次查询的费用，并在[各套餐的限制](/rate-limits#limits-by-plan)中查看您套餐的限流规则。
- 阅读[从 Clearbit 迁移](/migration/clearbit/introduction)，了解所有 Clearbit 端点共有的变更。

## 端点映射

| Clearbit                                                         | Tomba                                              |
| ---------------------------------------------------------------- | -------------------------------------------------- |
| `GET https://person.clearbit.com/v2/combined/find?email=`        | `GET https://api.tomba.io/v1/combined/find?email=` |
| `GET https://person-stream.clearbit.com/v2/combined/find?email=` | `GET https://api.tomba.io/v1/combined/find?email=` |

## 认证变更

Clearbit 将密钥作为基本认证的用户名或 Bearer 令牌接收。Tomba 需要 `X-Tomba-Key` 和 `X-Tomba-Secret` 这 2 个请求头：

```bash
# Clearbit
curl "https://person.clearbit.com/v2/combined/find?email=jane.doe@stripe.com" \
  -H "Authorization: Bearer $CLEARBIT_API_KEY"

# Tomba
curl "https://api.tomba.io/v1/combined/find?email=jane.doe@stripe.com" \
  -H "X-Tomba-Key: $TOMBA_API_KEY" \
  -H "X-Tomba-Secret: $TOMBA_SECRET_KEY"
```

Tomba 的 API 密钥会过期；请参考[密钥过期](/authentication#key-expiry)规划轮换。

## 参数映射

| Clearbit                                                                                                              | Tomba         | 备注                                                                                                                                                      |
| --------------------------------------------------------------------------------------------------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `email`                                                                                                               | `email`       | 必填。                                                                                                                                                  |
| `webhook_url`                                                                                                         | `webhook_url` | Tomba 仍会在响应中返回结果，并在找到人员时另外通过 POST 发送一份副本。请参阅[单次请求回调](/webhook#per-request-callbacks)。 |
| `webhook_id`                                                                                                          | 无对应项 |                                                                                                                                                            |
| `given_name`, `family_name`, `ip_address`, `location`, `company`, `company_domain`, `linkedin`, `twitter`, `facebook` | 无对应项 | Tomba 仅根据邮箱地址进行匹配。                                                                                                                   |
| `subscribe`, `suppression`                                                                                            | 无对应项 |                                                                                                                                                            |
| `API-Version` 请求头                                                                                                  | 无对应项 |                                                                                                                                                            |

## 响应字段映射

| Clearbit      | Tomba          | 备注                                                                                                                                     |
| ------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `person`      | `data.person`  | 始终为对象。当 Tomba 没有该地址对应的人员时，整个响应为 `not_found`；请参阅[错误映射](#error-mapping)。       |
| `company`     | `data.company` | 当 Tomba 没有该人员所在域名对应的公司时，返回一个所有字段均为 `null` 的对象，而不是 `null` 本身。请检查 `data.company.domain`。 |
| 无对应项 | `meta.email`   | 您查询的地址。未找到公司时为空字符串。                                                                     |

在 `data.person` 和 `data.company` 内部，字段按 Person 和 Company 指南中的说明映射：

- [Person API 响应字段](/migration/clearbit/person-api#response-field-mapping)
- [Company API 响应字段](/migration/clearbit/company-api#response-field-mapping)

## 状态映射

Clearbit 的 Combined API 没有可送达性状态。Tomba 额外提供 `data.person.verification`，其中包含该地址最近一次验证的 `date` 和 `status`。该状态使用邮箱验证器的取值，详见[状态值](/attributes/verifier#status-values)；如果该地址尚未验证，则为 `null`。比较时请忽略大小写。

## 错误映射

| Clearbit                  | Tomba                                                                                                                                                     | 建议操作                                                                                                                                |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `202` 查询已排队       | 不会返回                                                                                                                                              | 删除遇到 `202` 时重试的逻辑。                                                                                                          |
| 只有 `company` 的 `200` | `200`，带有 `errors` 对象：`type` 为 `not_found`，`code` 为 404                                                                                             | Tomba 需要人员信息。如果仍想获取公司信息，请使用该地址的域名调用 [`GET /v1/companies/find`](/api/enrichment#company-api)。 |
| `404` 人员和公司均未找到       | `200`，带有 `errors` 对象：`type` 为 `not_found`，`code` 为 404                                                                                             | 检查响应体中是否有 `errors`，而不只是检查状态码。                                                                                         |
| `422` 验证错误    | 地址格式错误时返回 `422 params_invalid`。一次性邮箱或网页邮箱地址返回 `200`，带有 `errors` 对象：`type` 为 `params_invalid`，`code` 为 422。 | 请发送工作邮箱地址。                                                                                                                      |
| `401` API 密钥无效     | `400 authentication_failed`（缺失或格式错误）、`400 api_key_expired`、`401 authentication_failed`（密钥或 Secret 错误）                              | 检查这两个请求头；[轮换](/authentication#rotate-keys)已过期的密钥。                                                                 |
| `402` 超出配额          | `402 quota_exceeded`                                                                                                                                      | 等待您的用量周期更新，或添加积分。                                                                                       |
| `429` 速率限制          | `429 rate_limit`                                                                                                                                          | 在 `Retry-After` 指定的延迟后重试；请参阅[处理 429 响应](/rate-limits#handle-429-responses)。                                       |
| 无对应项             | `451 claimed_email`                                                                                                                                       | 该地址的所有者已要求 Tomba 停止处理该地址。请将其从您的数据中删除。                                                     |
| `50X`                     | `500 api_error`                                                                                                                                           | 使用退避策略重试。                                                                                                                       |

错误响应不消耗积分。所有类型都列在[错误](/error-handling#error-types)中。

## 批量任务和异步任务

Tomba 以同步方式响应每次组合查询，因此请删除 `202` 重试。`webhook_url` 回调携带与响应相同的 JSON，但没有 Clearbit 的 `id`、`type` 和 `status` 外层包装，并且未签名。

没有用于组合查询的批量类型。如需处理列表，请为地址运行 `enrich` 任务，为其域名运行 `company` 任务；请参阅[邮箱数据丰富](/bulks#email-enrichment)和[公司数据丰富](/bulks#company-enrichment)。每个任务都需要创建、启动、轮询，并以 CSV 格式下载；请参阅[生命周期](/bulks#lifecycle)。

## 代码示例

此函数替代一次 Combined API 查询，并返回 Clearbit 的 `{person, company}` 结构；当 Tomba 没有公司信息时，`company` 设为 `null`。需要 Node.js 18 或更高版本。

```js title="find-combined.mjs"
const TOMBA_HEADERS = {
    "X-Tomba-Key": process.env.TOMBA_API_KEY,
    "X-Tomba-Secret": process.env.TOMBA_SECRET_KEY,
};

async function findCombined(email) {
    const url = new URL("https://api.tomba.io/v1/combined/find");
    url.searchParams.set("email", email);
    const res = await fetch(url, { headers: TOMBA_HEADERS });
    const body = await res.json();
    if (body.errors) {
        // No person found, or a disposable or webmail address: HTTP 200 with an errors object.
        if (res.ok) return { person: null, company: null };
        throw new Error(
            `${res.status} ${body.errors.type}: ${body.errors.message}`,
        );
    }
    const { person, company } = body.data;
    // Tomba returns an object with null fields when it has no company.
    return { person, company: company.domain ? company : null };
}

const { person, company } = await findCombined("jane.doe@stripe.com");
console.log(person?.name.fullName, company?.name ?? "no company");
```

## 切换检查清单

1. 将 Tomba 密钥和 Secret 存储为 `TOMBA_API_KEY` 和 `TOMBA_SECRET_KEY`，并以 `X-Tomba-Key` 和 `X-Tomba-Secret` 发送，取代基本认证或 Bearer 令牌。
2. 仅使用邮箱地址调用 `https://api.tomba.io/v1/combined/find`，并读取 `data.person` 和 `data.company`。
3. 将带有 `errors` 对象的 `200` 响应视为未找到，并检查 `data.company.domain`，而不是测试 `company` 是否为 `null`。
4. 如果您依赖仅含公司的结果，请添加对 `/v1/companies/find` 的回退调用。
5. 按照 [Person](/migration/clearbit/person-api) 和 [Company](/migration/clearbit/company-api) 指南应用人员和公司字段的变更，并删除 `202` 重试。
6. 处理 `402`，在 `Retry-After` 之后重试 `429`，并删除返回 `451` 的地址。
7. 在切换生产流量之前，用两个服务查询同一批样本地址，并比较您使用的字段。
