CirculeID

API reference

按资源分组的每一个端点

护照、事件、凭证与解析。下述错误约定、分页与幂等性规则,对这四者一体适用。

基础 URL
api.circuleid.com
版本
/v1
认证
Bearer

Definition

护照 API 提供哪些端点?

四组。护照类端点负责签发、读取、更新产品记录并进行版本管理。事件类端点负责追加与查询 EPCIS 2.0 事件。凭证类端点负责签发、验证与吊销签名声明。解析类端点提供扫描数据载体后所走的公开 GS1 Digital Link 路径。

If you have not read the API model yet, start there. The relationships between these four decide which one you should be calling, and that is the choice most integrations get wrong first.

端点

护照

产品记录及其访问策略。多数集成最终调用最频繁的,是缺口端点。
Passports endpoints
方法PathPurpose
POST/v1/passportsIssue a passport against a GS1 identifier
GET/v1/passports/{id}Read the full record your key is entitled to
PATCH/v1/passports/{id}Update the record; material changes are versioned
GET/v1/passports/{id}/gapsFields the product group’s delegated act still requires
GET/v1/passports/{id}/versionsThe record’s version history
GET/v1/passportsList and filter passports in your tenant

端点

事件

仅追加的 EPCIS 2.0 历史。历史数据回补请使用批量接口;单条接口针对时延而非吞吐量做了优化。
Events endpoints
方法PathPurpose
POST/v1/eventsAppend one EPCIS 2.0 event
POST/v1/events/bulkAsynchronous bulk ingestion; returns a job
GET/v1/eventsQuery by object identity, business step or time
GET/v1/jobs/{id}Status of a bulk ingestion job

端点

凭证

已签名的声明。任何持有该凭证的人都可以验证,且不需要这些端点 —— 它们只是便利,而非依赖。
Credentials endpoints
方法PathPurpose
POST/v1/credentialsIssue a signed claim against a passport
GET/v1/credentials/{id}Retrieve a credential and its status
POST/v1/credentials/{id}/revokeRevoke; verification fails from this point
POST/v1/credentials/verifyVerify a credential you were presented

端点

解析

公开路径。无需认证、可缓存,并返回调用方凭证所对应的层级。
Resolution endpoints
方法PathPurpose
GET/01/{gtin}GS1 Digital Link resolution — the path a scan takes
GET/01/{gtin}/21/{serial}Resolution for an item-level passport

约定

错误、分页与幂等性

这些适用于上述所有端点。在客户端统一处理一次,好过在每个调用点分别处理。
约定
# Validation errors return every problem at once.
HTTP/1.1 422 Unprocessable Entity
{
  "error": "validation_failed",
  "problems": [
    { "field": "materials[0].share", "constraint": "must sum to 1.0" },
    { "field": "carbonFootprint.method", "constraint": "required for this group" }
  ]
}

# Pagination is cursor-based: an offset would skip or repeat
# records as new events arrive while you are reading.
GET /v1/events?object=01/09506000134352&cursor=ev_8f21...

# Send an idempotency key on any write you might retry.
POST /v1/passports
Idempotency-Key: 6f1c9a7e-...   # a repeat returns the original result

答疑

常见问题

错误响应长什么样?

返回常规的 HTTP 状态码,并附带结构化响应体,指明错误、未通过校验的字段以及被违反的约束。校验错误一次性全部返回,而非逐条给出,因此格式有误的产品记录会在一次响应中暴露全部问题,而不必往返五次。

分页如何处理?

采用游标而非偏移量。事件历史在您读取期间仍在增长,使用偏移量会随着新事件的到来而悄悄跳过或重复记录。游标是不透明且稳定的;请传入上一页返回的游标,直到不再返回游标时停止。

写操作是幂等的吗?

可以,而且应当如此。对任何可能重试的写入请附带幂等键;使用相同键的重复请求会返回原始结果,而不会创建第二份护照或重复事件。若没有幂等键,写入时的网络超时会让您无从判断该操作是否已生效。

读取护照与解析护照有什么区别?

读取需要认证,并只返回您的 API 密钥所对应的内容。解析则是扫描所做的事:公开、匿名、可缓存,并返回调用方凭证所允许的层级 —— 对多数调用方而言就是公开层级。二者是不同的路径,性能与隐私特性也不同。

Next step

用沙箱密钥签发一份

评判一个 API 最快的方法,是向它发送一条真实的产品记录,然后读取返回的内容。

Index