Waafir
本页面为机器翻译,尚待人工审核,可能存在错误。

按外部 ID 核对数据

本方案展示如何为一次摄取提交形成闭环:通过您自己(调用方)提供的标识符确认某一特定行已落库,并核验每个实体的汇总计数与您提交的内容一致。这两种读取都限定在组织范围内,绝不会暴露其他租户的数据。

为什么对账很重要

今天您向 Waafir 发送了一个包含 1,200 笔还款的 NDJSON 文件。导入以 succeeded 结束,并带有 rowCountSucceeded: 1200。这是一个信号。对账读取则为您提供两个更有力的信号:

  • 按调用方 ID 抽查——挑选一笔您的团队关心的还款,用您自己的 external_id 查找它,确认其值与您提交的内容一致。您的标识符才是权威的引用依据,而不是 Waafir 的内部 UUID。
  • 按实体汇总计数——确认 Waafir 当天有效数据行的计数与您的权威数据源计数一致。“我今天提交了 1,200 笔还款;计数显示今天创建了 1,200 笔。对账完成。”

这些读取对缓存是安全的(单笔贷款查询使用 Cache-Control: private, no-store),因此响应反映的是最新写入。在导入后立即对账,返回的就是刚刚落库的状态。

两个端点

  • GET /api/v1/monitoring/loan/loans/{externalId}?portfolioId=…——按您自己的 external_id 对单笔贷款进行对账。返回贷款正文以及经过掩码处理的借款人上下文,让您无需第二次请求即可核实该贷款关联的是您预期的借款人。
  • GET /api/v1/monitoring/loan/counts?date=YYYY-MM-DD&portfolioId=…&entity=…——按实体的行计数。不带 entity 时,返回全部六个贷款领域实体的计数;带 entity 时,只返回该实体的计数。date 参数会在历史累计计数之外再增加一个 onDate 计数。

对于不存在的行,以及存在于其他组织中的行,这两个端点都返回 404——Waafir 绝不会确认或否认其他租户数据的存在。

方案

# curl — reconcile a single loan and verify per-entity counts
set -euo pipefail

PAT="${WAAFIR_PAT}"
BASE_URL="${WAAFIR_BASE_URL:-https://app.waafir.io}"
PORTFOLIO_ID="${WAAFIR_PORTFOLIO_ID}"
EXTERNAL_LOAN_ID="L-2026-05-22-1234"
TODAY="2026-05-22"

# Step 1 — single-loan reconciliation. The external_id is URL-encoded
# automatically by curl when passed as a positional path segment.
curl -fsS \
  "${BASE_URL}/api/v1/monitoring/loan/loans/${EXTERNAL_LOAN_ID}?portfolioId=${PORTFOLIO_ID}" \
  -H "Authorization: Bearer ${PAT}" \
  | jq '{loan: {externalId: .loan.externalId, principalAmount: .loan.principalAmount, status: .loan.status, disbursementDate: .loan.disbursementDate}, borrower: {externalId: .borrower.externalId, name: .borrower.name, countryCode: .borrower.countryCode}}'

# Step 2 — full per-entity counts for the portfolio.
curl -fsS \
  "${BASE_URL}/api/v1/monitoring/loan/counts?portfolioId=${PORTFOLIO_ID}&date=${TODAY}" \
  -H "Authorization: Bearer ${PAT}" \
  | jq

# Step 3 — counts for just the payments entity (narrower request).
curl -fsS \
  "${BASE_URL}/api/v1/monitoring/loan/counts?portfolioId=${PORTFOLIO_ID}&date=${TODAY}&entity=actual_payments" \
  -H "Authorization: Bearer ${PAT}" \
  | jq
// TypeScript — reconcile a single loan and verify per-entity counts
const PAT = process.env.WAAFIR_PAT!;
const BASE_URL = process.env.WAAFIR_BASE_URL ?? "https://app.waafir.io";
const portfolioId = process.env.WAAFIR_PORTFOLIO_ID!;
const externalLoanId = "L-2026-05-22-1234";
const today = "2026-05-22";

const auth = { Authorization: `Bearer ${PAT}` };

// Step 1 — single-loan reconciliation.
const loanRes = await fetch(
    `${BASE_URL}/api/v1/monitoring/loan/loans/${encodeURIComponent(externalLoanId)}?portfolioId=${portfolioId}`,
    { headers: auth },
);
if (loanRes.status === 404) throw new Error(`loan ${externalLoanId} not found in portfolio ${portfolioId}`);
if (!loanRes.ok) throw new Error(`reconcile failed: ${loanRes.status}`);
const loanBody = (await loanRes.json()) as {
    loan: { externalId: string; principalAmount: string; status: string; disbursementDate: string };
    // borrower may be null if a referential-integrity edge case dropped
    // the borrower row; the response is a partial projection in that case.
    borrower: {
        externalId: string;
        name: string;            // masked (e.g. "M*** S. L."), empty when absent
        countryCode: string | null;
    } | null;
};
console.log({
    loan: {
        externalId: loanBody.loan.externalId,
        principalAmount: loanBody.loan.principalAmount,
        status: loanBody.loan.status,
        disbursementDate: loanBody.loan.disbursementDate,
    },
    borrower: loanBody.borrower
        ? {
              externalId: loanBody.borrower.externalId,
              name: loanBody.borrower.name,
              countryCode: loanBody.borrower.countryCode,
          }
        : null,
});

// Step 2 — full per-entity counts.
const countsRes = await fetch(
    `${BASE_URL}/api/v1/monitoring/loan/counts?portfolioId=${portfolioId}&date=${today}`,
    { headers: auth },
);
console.log("counts:", await countsRes.json());

// Step 3 — narrow to a single entity.
const paymentsRes = await fetch(
    `${BASE_URL}/api/v1/monitoring/loan/counts?portfolioId=${portfolioId}&date=${today}&entity=actual_payments`,
    { headers: auth },
);
console.log("payments:", await paymentsRes.json());
# python — reconcile a single loan and verify per-entity counts
import os
import urllib.parse
import requests

PAT = os.environ["WAAFIR_PAT"]
BASE_URL = os.environ.get("WAAFIR_BASE_URL", "https://app.waafir.io")
portfolio_id = os.environ["WAAFIR_PORTFOLIO_ID"]
external_loan_id = "L-2026-05-22-1234"
today = "2026-05-22"

auth = {"Authorization": f"Bearer {PAT}"}

# Step 1 — single-loan reconciliation. external_id can contain hyphens
# and other URL-safe chars; encode defensively in case yours contain slashes.
encoded = urllib.parse.quote(external_loan_id, safe="")
loan = requests.get(
    f"{BASE_URL}/api/v1/monitoring/loan/loans/{encoded}",
    params={"portfolioId": portfolio_id},
    headers=auth,
    timeout=30,
)
if loan.status_code == 404:
    raise SystemExit(f"loan {external_loan_id} not found in portfolio {portfolio_id}")
loan.raise_for_status()
body = loan.json()
print({
    "loan": {
        "externalId": body["loan"]["externalId"],
        "principalAmount": body["loan"]["principalAmount"],
        "status": body["loan"]["status"],
        "disbursementDate": body["loan"]["disbursementDate"],
    },
    "borrower": {
        "externalId": body["borrower"]["externalId"],
        "name": body["borrower"]["name"],
        "countryCode": body["borrower"]["countryCode"],
    },
})

# Step 2 — full per-entity counts.
counts = requests.get(
    f"{BASE_URL}/api/v1/monitoring/loan/counts",
    params={"portfolioId": portfolio_id, "date": today},
    headers=auth,
    timeout=30,
).json()
print("counts:", counts)

# Step 3 — narrow to one entity.
payments = requests.get(
    f"{BASE_URL}/api/v1/monitoring/loan/counts",
    params={"portfolioId": portfolio_id, "date": today, "entity": "actual_payments"},
    headers=auth,
    timeout=30,
).json()
print("payments:", payments)

验证要点

对于单笔贷款响应,您以 external_id 提交的每个字段都应原样返回:principalAmount、currencyCode、interestRateApr、disbursementDate、termMonths、repaymentFrequency、productType、status、metadata。借款人部分会按照 Waafir 的个人身份信息(PII)政策进行掩码处理——在此端点上,name、email、phone 和 nationalIdLast4 默认会被掩码;非 PII 字段(countryCode、dob、gender、incomeBand、employmentStatus)则原样传递。

对于计数响应,总数限定在您的组织范围内,并排除已软删除的行。使用 ?date=YYYY-MM-DD 时,每个实体的条目除历史累计总数外,还包含一个 onDate 计数——即在该日期创建的行。onDate 计数就是您用来确认与提交内容相符的信号。

单笔贷款端点返回 404 始终意味着该贷款在该投资组合中对您的组织不可见。它可能根本不存在,也可能存在于另一个组织下;响应有意不加以区分。