获取可重用文档
使用此端点检查用户是否已有可重用的文档,然后再启动新的文档采集流程。如果找到文档,可以将其 documentId 直接传递给 POST /processes/v1(Document 类型)以跳过采集步骤。
端点
| 环境 | URL |
|---|---|
| Production | GET https://api.id.unico.app/documents/v1 |
| Sandbox | GET https://api.id.uat.unico.app/documents/v1 |
请求
请求头
| 请求头 | 值 |
|---|---|
Authorization | Bearer <access_token>(参见身份验证) |
APIKEY | 已启用文档采集与重用功能的已配置 API 密钥。 |
查询参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
code | string | 是 | 人员的标识符,不含格式化字符(例如 CPF)。 |
type | string | 是 | code 中标识符的类型。请使用 BR_CPF。其他标识符类型(例如 MX_CURP)仅在为您的 API 密钥启用后才会被接受。 |
备注
type 标识的是人员,而非文档。响应会列出该人员可重用的每一种文档类型。
示例
- cURL
- Node.js
curl -X GET "https://api.id.unico.app/documents/v1?code=12345678909&type=BR_CPF" \
-H "Authorization: Bearer $TOKEN" \
-H "APIKEY: $API_KEY"
import fetch from 'node-fetch';
const params = new URLSearchParams({ code: '12345678909', type: 'BR_CPF' });
const res = await fetch(
`https://api.id.unico.app/documents/v1?${params}`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
APIKEY: apiKey
}
}
);
const data = await res.json();
// data.items[0].documentId → pass to POST /processes/v1 for reuse
响应
200 OK
{
"items": [
{
"documentType": "unico.moja.dictionary.br.cnh.v2.Cnh",
"documentId": "doc-abc-123"
}
]
}
| 字段 | 类型 | 描述 |
|---|---|---|
items | array | 该人员已有且可重用的文档:每种文档类型最多一份,即最新的一份。如果该人员没有可重用的文档,则为空。 |
items[].documentType | string | 文档类型,以字典名称表示(例如 unico.moja.dictionary.br.cnh.v2.Cnh)。可能的值请参见创建 Document 流程中的 document.type 值。 |
items[].documentId | string | 文档标识符。在 POST /processes/v1 中将此值传入 document.documentId 以重用该文档。 |
使用 documentId 进行文档重用
获取 documentId 后,将其传入 Document 流程请求中以跳过采集步骤:
{
"subject": {
"code": "12345678909",
"name": "Luke Skywalker"
},
"document": {
"purpose": "onboarding",
"authProcessId": "<biometric-process-id>",
"documentId": "doc-abc-123"
}
}
| 字段 | 描述 |
|---|---|
document.purpose | 此文档流程的业务用途。可接受的值:creditprocess、carpurchase、paybypaycheck、onboarding、fgts。这些值专用于 Document API,与生物识别 SDK 的 purpose 枚举不同。 |
document.authProcessId | 之前为该用户创建的生物识别流程的 ID(来自 POST /processes/v1)。 |
document.documentId | 从此端点响应中获取的文档 ID。提供此参数后,可以省略 document.files — 平台会自动检索之前采集的文档。 |
有关完整的 Document 流程请求模式,请参见创建 Document 流程。
错误代码
- 400 Bad Request
- 403 Forbidden
- 429 Too Many Requests
- 500 Internal Server Error
| 代码 | 消息 | 描述 |
|---|---|---|
20507 | The subject.code field is invalid. | 缺少 code 或 type。 |
99989 | The document is invalid. | code 中的标识符对于 type 中的类型无效(例如校验位错误的 CPF)。 |
20069 | The subject.duitype field is invalid. | type 中的值不是已知的标识符类型。仅当您的 API 密钥接受 BR_CPF 以外的标识符类型时才会返回。 |
400 | HolderCodeType: argument is invalid. | type 不是 BR_CPF,且您的 API 密钥不接受其他标识符类型。 |
20002 | The APIKEY header is missing. | 缺少 APIKEY 请求头。 |
20001 | The authorization token is missing. | 缺少身份验证令牌请求头。 |
Bearer 令牌或 APIKEY 缺失、已过期或无效。
| 代码 | 消息 | 描述 |
|---|---|---|
30017 | User does not have permission to perform this action. | JWT 格式错误或用户没有执行此操作的权限。 |
10502 | O token informado está expirado. | 访问令牌已过期。 |
10501 | O token informado é inválido. | 身份验证令牌无效。 |
10201 | O AppKey informado é inválido. | APIKEY 缺失或不存在。 |
已达到速率限制。当您的系统收到 HTTP 429 错误时,必须实施机制以防止级联故障并避免加重限制。
最佳实践:
- 冷却期(backoff): 立即停止或限制系统的后续请求。不要在紧密循环中持续重试失败的请求。
- 排队与限流(Queueing & throttling): 在您的一侧缓冲或排队传出请求,以便在重新发送之前控制流量。
- 带抖动的指数退避(Exponential backoff with jitter): 重试时,在尝试之间以指数方式增加等待时间(例如,1秒、2秒、4秒、8秒),并添加一个小的随机延迟("抖动"),以防止所有排队请求在完全相同的毫秒重试的羊群效应。
警告
在未应用退避的情况下持续请求受速率限制的端点,可能会延长限制期并严重影响系统的运行吞吐量。在您的一侧正确限流请求可确保更顺畅、更具弹性的集成。
有关默认限制、增加请求及其他详细信息,请参阅速率限制。
| 代码 | 消息 | 描述 |
|---|---|---|
99999 | Internal failure! Try again later. | 服务器端处理错误。 |