building-apis
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<!-- TIER:1 -->
<!-- TIER:1 -->
Building APIs
构建API
An API is a RESTful endpoint that exposes integration logic for external consumption. External systems call the API over HTTP; the API processes the request through lookups and imports, then returns a structured response. Concerns when building an API:
- Mode selection -- builder (visual configuration) vs script (full JavaScript control)
- Request definition -- HTTP method, URI path, parameters, body schema, request transformation
- Processing pipeline -- routers and page processors (lookups + imports) that execute business logic
- Response routing -- directing processed data to the correct response definition based on success/failure or custom conditions
- Response shaping -- status codes, field mappings, body schema, hooks (preMap, postMap) on each response
- Response mapping -- extracting fields from each page processor's response back into the record for downstream steps. Configured on each entry, same as in flows. For lookup exports the response has
pageProcessors[]anddata[](useerrors[]for single results). For imports the response is viadata[0].fieldName(use_json)_json.fieldName - postResponseMap hook -- JavaScript processing after response mapping, configured on entries
pageProcessors[]
Used across integrations alongside flows and tools. APIs do not have their own authentication -- incoming requests authenticate via the Celigo API token; outbound calls to external systems use the connections referenced by exports/imports in the pipeline.
API是一种RESTful endpoint,对外暴露供外部调用的集成逻辑。外部系统通过HTTP调用该API;API通过查询和导入处理请求,然后返回结构化响应。构建API时需要关注以下事项:
- 模式选择——构建器(可视化配置)vs 脚本(完全JavaScript控制)
- 请求定义——HTTP方法、URI路径、参数、请求体 schema、请求转换
- 处理流水线——执行业务逻辑的路由器和页面处理器(查询+导入)
- 响应路由——根据成功/失败状态或自定义条件,将处理后的数据导向正确的响应定义
- 响应塑造——每个响应的状态码、字段映射、响应体 schema、钩子(preMap、postMap)
- 响应映射——从每个页面处理器的响应中提取字段,放回记录供下游步骤使用。在每个条目上配置,与流程中的配置方式相同。对于查询导出,响应包含
pageProcessors[]和data[](单结果使用errors[])。对于导入,响应通过data[0].fieldName获取(使用_json)_json.fieldName - postResponseMap钩子——响应映射后的JavaScript处理,配置在条目上
pageProcessors[]
API与流程、工具一起用于各类集成场景。API没有独立的认证机制——传入请求通过Celigo API令牌进行认证;对外部系统的出站调用使用流水线中导出/导入所引用的连接。
The Request IS the Source Record
请求即源记录
APIs are invoked by an external HTTP caller -- there is no upstream export, no scheduler, no listener feeding them. That has three design consequences:
- The request stage is the input shape. Whatever the caller sends (body, path params, query params, headers) is what downstream processing sees as the record. There is no upstream pipeline to reshape it first -- use the request if the envelope needs reshaping before routing.
transform - The response stage is the output. Whatever the selected response definition produces is exactly what the caller receives. Nothing runs after it.
- No self-starting. APIs have no , no listener, and none of the flow runtime controls (
schedule,proceedOnFailure, chaining). "Every night at 2 AM, do X" is a flow -- possibly one that calls the API, but the schedule lives on the flow. Retry-after-failure is the caller's decision.skipRetries
When a flow needs to invoke an API, it does so as an ordinary HTTP caller (an HTTP export/import pointing at the API's URL). There is no special flow-step-to-API wiring.
A top-level takes the API offline without deleting it -- callers get a 404 until it's re-enabled.
disabled: trueAPI由外部HTTP调用者触发——没有上游导出、调度器或监听器为其提供数据。这带来三个设计影响:
- 请求阶段为输入格式。调用者发送的所有内容(请求体、路径参数、查询参数、请求头)就是下游处理所看到的记录。没有上游流水线先对其进行重塑——如果需要在路由前重塑请求结构,请使用请求。
transform - 响应阶段为输出结果。所选响应定义生成的内容就是调用者收到的内容。响应之后没有其他操作。
- 无法自动启动。API没有、监听器,也没有流程运行时控制项(
schedule、proceedOnFailure、链式调用)。“每天凌晨2点执行X”属于流程范畴——流程可以调用API,但调度配置在流程上。失败后重试由调用者决定。skipRetries
当流程需要调用API时,它会作为普通HTTP调用者(指向API URL的HTTP导出/导入)进行调用。不存在特殊的流程步骤到API的连接机制。
设置顶层可让API下线而无需删除——调用者会收到404错误,直到API重新启用。
disabled: trueAPI Modes
API模式
Builder Mode (type: "builder"
)
type: "builder"构建器模式(type: "builder"
)
type: "builder"Visual configuration with discrete components:
API (type: "builder")
+-- request -- method, relativeURI, params, bodySchema, mockRequest, transform
+-- routers[] -- processing pipeline (same structure as flow routers)
| +-- branches[]
| +-- inputFilter -- when to use this branch (s-expression rules)
| +-- pageProcessors[] -- lookups (exports) and imports
| +-- nextRouterId -- chain to next router, or "apiRouter" to finish
+-- responseRouter -- id="apiRouter", routes processed data to a response
+-- responses[] -- success, fail, custom -- each with statusCode, inputFilter, mappingsThe incoming HTTP request replaces the export as data source. Routers and page processors work identically to flows.
通过离散组件进行可视化配置:
API (type: "builder")
+-- request -- 方法、relativeURI、参数、bodySchema、mockRequest、transform
+-- routers[] -- 处理流水线(与流程路由器结构相同)
| +-- branches[]
| +-- inputFilter -- 何时使用该分支(s-expression规则)
| +-- pageProcessors[] -- 查询(导出)和导入
| +-- nextRouterId -- 链接到下一个路由器,或设为"apiRouter"结束
+-- responseRouter -- id="apiRouter",将处理后的数据路由到响应
+-- responses[] -- 成功、失败、自定义——每个都包含statusCode、inputFilter、映射传入的HTTP请求替代导出作为数据源。路由器和页面处理器的工作方式与流程完全相同。
API Execution Pipeline (Builder Mode)
构建器模式下的API执行流水线
When an API receives a request:
- Request received -- method + path matched against the API endpoint definition
- Request transform (optional) -- reshapes the incoming request body before routing
- Router evaluation -- evaluates branch input filter conditions
routeRecordsUsing - Branch selection -- first matching branch processes the request
- Page processors -- each processor in the branch executes sequentially (export lookups, import writes)
- Response mapping -- on each processor carries data forward to the next processor
responseMapping - Response router -- (id="apiRouter") selects which response template to use based on response input filters
responseRouter - Response -- selected response template returned to the caller with its statusCode, headers, and body
当API收到请求时:
- 接收请求——将请求方法+路径与API端点定义匹配
- 请求转换(可选)——在路由前重塑传入的请求体
- 路由器评估——评估分支的输入过滤条件
routeRecordsUsing - 分支选择——第一个匹配的分支处理请求
- 页面处理器——分支中的每个处理器按顺序执行(导出查询、导入写入)
- 响应映射——每个处理器上的将数据传递给下一个处理器
responseMapping - 响应路由器——(id="apiRouter")根据响应输入过滤器选择要使用的响应模板
responseRouter - 返回响应——将所选响应模板及其statusCode、请求头、响应体返回给调用者
Script Mode (type: "script"
)
type: "script"脚本模式(type: "script"
)
type: "script"A single JavaScript function receives the request object (method, headers, queryParams, body, pathParams) and returns . Complete control with no visual configuration.
handleRequest{statusCode, headers, body}Legacy APIs (no field, top-level + ) exist in production but are not represented in the current spec. Distinguish by: if is absent/null and is present, it's legacy.
type_scriptIdfunctiontype_scriptId单个 JavaScript函数接收请求对象(method、headers、queryParams、body、pathParams)并返回。无需可视化配置,完全可控。
handleRequest{statusCode, headers, body}遗留API(无字段,顶层包含 + )仍在生产环境中使用,但未在当前规范中体现。判断方式:如果不存在/为null且存在,则为遗留API。
type_scriptIdfunctiontype_scriptIdQuick Reference
快速参考
Decision Matrix
决策矩阵
| Scenario | Mode | Why |
|---|---|---|
| Standard lookup/write with structured response | Builder | Visual debugging, test runs, structured responses |
| Multiple response shapes based on success/failure | Builder | Response router + inputFilter handles this declaratively |
| Complex conditional logic or custom auth validation | Script | Full JavaScript control over request/response |
| Dynamic routing that can't be expressed as input filters | Script | |
| Proxy through an authenticated connection | Builder | Wire the connection's export/import as a page processor |
| Simple webhook receiver that transforms and forwards | Builder | Single router, single branch, one import |
| 场景 | 模式 | 原因 |
|---|---|---|
| 带结构化响应的标准查询/写入 | 构建器 | 可视化调试、测试运行、结构化响应 |
| 基于成功/失败状态的多种响应格式 | 构建器 | 响应路由器+inputFilter可声明式处理 |
| 复杂条件逻辑或自定义认证验证 | 脚本 | 完全控制请求/响应的JavaScript能力 |
| 无法用输入过滤器表达的动态路由 | 脚本 | |
| 通过已认证连接代理请求 | 构建器 | 将连接的导出/导入作为页面处理器配置 |
| 转换并转发的简单Webhook接收器 | 构建器 | 单个路由器、单个分支、一个导入 |
Minimum Required Fields
必填字段
| Mode | Required Fields |
|---|---|
| Builder | |
| Script | |
| Legacy | |
| 模式 | 必填字段 |
|---|---|
| 构建器 | |
| 脚本 | |
| 遗留 | |
Schema Index
Schema索引
All schemas are in references/schemas/:
| Schema | What it defines |
|---|---|
| request.yml | Top-level API fields (name, type, version, disabled, builder/script refs) |
| response.yml | API response shape |
| builder.yml | Builder configuration (request, routers, responseRouter, responses refs) |
| api-request.yml | Request config (method, relativeURI, params, bodySchema, mockRequest, transform) |
| api-response.yml | Response definitions (id, name, type, statusCode, inputFilter, mappings, hooks) |
| response-router.yml | Response router (id="apiRouter", routeRecordsUsing) |
| router.yml | Routers (branches, inputFilter, pageProcessors) |
| script.yml | Script config (_scriptId, function) |
| apim.yml | APIM metadata (publication status) |
| shipworks.yml | Legacy ShipWorks auth |
所有Schema都在references/schemas/中:
| Schema | 定义内容 |
|---|---|
| request.yml | 顶层API字段(名称、类型、版本、禁用状态、构建器/脚本引用) |
| response.yml | API响应格式 |
| builder.yml | 构建器配置(请求、路由器、响应路由器、响应引用) |
| api-request.yml | 请求配置(方法、relativeURI、参数、bodySchema、mockRequest、transform) |
| api-response.yml | 响应定义(id、名称、类型、statusCode、inputFilter、映射、钩子) |
| response-router.yml | 响应路由器(id="apiRouter"、routeRecordsUsing) |
| router.yml | 路由器(分支、inputFilter、pageProcessors) |
| script.yml | 脚本配置(_scriptId、function) |
| apim.yml | APIM元数据(发布状态) |
| shipworks.yml | 遗留ShipWorks认证 |
Related Skills
相关技能
- configuring-exports > Quick Reference -- building lookup exports used as page processors in the API pipeline
- configuring-imports > Quick Reference -- building imports used as page processors in the API pipeline
- building-flows > How to Build a Flow -- flows share the same router/branch/pageProcessor pipeline mechanics
- writing-scripts > Quick Reference -- writing (script-mode APIs),
handleRequest/preMaphooks, andpostMappostResponseMap - writing-handlebars > Quick Reference -- dynamic expressions in request bodies, URIs, and response mappings
- configuring-filters > Quick Reference -- input filters on router branches to conditionally route records
- configuring-exports > 快速参考——构建API流水线中用作页面处理器的查询导出
- configuring-imports > 快速参考——构建API流水线中用作页面处理器的导入
- building-flows > 如何构建流程——流程与API共享相同的路由器/分支/pageProcessor流水线机制
- writing-scripts > 快速参考——编写(脚本模式API)、
handleRequest/preMap钩子和postMappostResponseMap - writing-handlebars > 快速参考——请求体、URI和响应映射中的动态表达式
- configuring-filters > 快速参考——路由器分支上的输入过滤器,用于条件路由记录
How to Build an API
如何构建API
1. Plan what the API needs to do
1. 规划API的功能
Before creating anything, understand the requirements: what endpoint the caller needs, what data it sends, what systems are involved, what the response should look like. This determines everything -- mode, pipeline shape, which connections/exports/imports are needed.
创建前,先明确需求:调用者需要什么端点、发送什么数据、涉及哪些系统、响应应是什么格式。这将决定所有事项——模式、流水线结构、所需的连接/导出/导入。
2. Decide the mode
2. 选择模式
Use builder for most APIs -- it provides visual debugging, test runs, and structured responses. Use script only when the processing logic is too dynamic for the visual pipeline (e.g., complex conditional responses, custom auth validation, dynamic routing).
大多数API使用构建器模式——它提供可视化调试、测试运行和结构化响应。仅当处理逻辑过于动态,无法用可视化流水线实现时(例如复杂条件响应、自定义认证验证、动态路由),才使用脚本模式。
3. Check for existing resources
3. 检查现有资源
Look for connections, exports, and imports that can be reused before creating new ones.
bash
undefined创建新资源前,先寻找可复用的连接、导出和导入。
bash
undefinedSearch across all resource types in the account
在账户中搜索所有资源类型
celigo account search "<keyword>"
celigo account search "<keyword>"
Show what an existing API uses (exports, imports, connections)
查看现有API使用的资源(导出、导入、连接)
celigo account dependencies api <id>
celigo account dependencies api <id>
Find orphaned resources that could be reused
查找可复用的孤立资源
celigo account lint
celigo account lint
Search for APIs already in the account for patterns
搜索账户中已有的API,寻找参考模式
celigo apis list | grep -i "<keyword>"
celigo apis list | grep -i "<keyword>"
Check existing exports/imports that could serve as pipeline steps
检查可作为流水线步骤的现有导出/导入
celigo exports list | grep -i "<system-name>"
celigo imports list | grep -i "<system-name>"
celigo exports list | grep -i "<system-name>"
celigo imports list | grep -i "<system-name>"
Search marketplace for pre-built integration templates
在市场中搜索预构建的集成模板
celigo templates marketplace
The account index auto-refreshes when stale (>4 hours). Force a fresh snapshot with `celigo account snapshot`.celigo templates marketplace
账户索引会在过时(超过4小时)时自动刷新。使用`celigo account snapshot`强制生成新快照。4. Create the supporting resources (bottom-up)
4. 创建支撑资源(自底向上)
APIs reference exports and imports as page processors -- these must exist before you can attach them. Build order:
- Connections -- create or reuse connections to the target systems
- Exports -- for lookups that query external systems (use skill)
configuring-exports - Imports -- for writes to external systems (use skill)
configuring-imports
API将导出和导入作为页面处理器引用——这些资源必须先存在,才能附加到API。构建顺序:
- 连接——创建或复用与目标系统的连接
- 导出——用于查询外部系统(使用技能)
configuring-exports - 导入——用于写入外部系统(使用技能)
configuring-imports
5. Define the request (builder mode)
5. 定义请求(构建器模式)
Choose the HTTP method and URI path. GET and POST are most common; PUT and PATCH are rare.
- Path parameters use colon notation:
/customers/:id - Document query parameters, path parameters, headers, and body schema
- Add a for testing the pipeline without live calls
mockRequest - Optionally add a request (expression-based or script-based) to reshape incoming data before processing
transform
选择HTTP方法和URI路径。GET和POST最常用;PUT和PATCH较少使用。
- 路径参数使用冒号表示法:
/customers/:id - 记录查询参数、路径参数、请求头和请求体schema
- 添加用于在无需实际调用的情况下测试流水线
mockRequest - 可选添加请求(基于表达式或脚本),在处理前重塑传入数据
transform
6. Build the processing pipeline
6. 构建处理流水线
The pipeline is made of routers, branches, and page processors. See router.yml for the full schema.
Every builder API needs at least one router -- it's the container that holds branches, and branches hold the page processors that do the actual work. Use multiple branches when different request conditions need different processing paths (e.g., branch by HTTP method, request field value, or record type). Use multiple routers when you need sequential stages of processing where each stage can branch independently.
For pass-through routers (single branch, no filters, just linear steps before a branching router), omit and -- including them makes it appear as a filter-based branch in the UI. The API defaults are sufficient.
routeRecordsTorouteRecordsUsingInput filters use s-expression syntax: . Type wrappers (, , ) are required around and accessors. Logical combinators: , .
["operator", ["type", ["extract", "field"]], value]stringnumberbooleanextractcontext["and", cond1, cond2]["or", cond1, cond2]The last branch in the chain must set to reach the response router.
nextRouterId: "apiRouter"流水线由路由器、分支和页面处理器组成。完整Schema请查看router.yml。
每个构建器模式API至少需要一个路由器——它是容纳分支的容器,分支包含执行实际工作的页面处理器。当不同请求条件需要不同处理路径时(例如按HTTP方法、请求字段值或记录类型分支),使用多个分支。当需要多个独立分支的顺序处理阶段时,使用多个路由器。
对于直通路由器(单个分支、无过滤器,仅为分支路由器前的线性步骤),省略和——添加这些会使其在UI中显示为基于过滤器的分支。API默认配置已足够。
routeRecordsTorouteRecordsUsing输入过滤器使用s-expression语法:。和访问器必须包裹在类型包装器(、、)中。逻辑组合器:、。
["operator", ["type", ["extract", "field"]], value]extractcontextstringnumberboolean["and", cond1, cond2]["or", cond1, cond2]链中的最后一个分支必须设置以到达响应路由器。
nextRouterId: "apiRouter"7. Configure responses
7. 配置响应
Every builder API needs exactly one response and one response. Add responses for specific scenarios (e.g., 404 not found, 422 validation error).
successfailcustomEach response has:
- (HTTP status code)
statusCode - to determine when it's selected (typically
inputFilterfor success)["equals", ["boolean", ["context", "success"]], true] - to shape the response body from the processed record
mappings - Optional for documentation,
bodySchema,headers, andlookups(preMap, postMap)hooks
每个构建器模式API必须有一个响应和一个响应。可为特定场景添加响应(例如404未找到、422验证错误)。
successfailcustom每个响应包含:
- (HTTP状态码)
statusCode - 用于确定何时选择该响应(成功响应通常使用
inputFilter)["equals", ["boolean", ["context", "success"]], true] - 用于根据处理后的记录塑造响应体
mappings - 可选的(用于文档)、
bodySchema、headers和lookups(preMap、postMap)hooks
8. Configure the response router
8. 配置响应路由器
Set and choose routing method:
id: "apiRouter"- (default) -- evaluates each response's
input_filtersinputFilter - -- custom JavaScript returns the response
scriptto useid
设置并选择路由方式:
id: "apiRouter"- (默认)——评估每个响应的
input_filtersinputFilter - ——自定义JavaScript返回要使用的响应
scriptid
9. Build the JSON
9. 构建JSON
Reference the Schema Index above for exact field schemas.
Every API needs at minimum: , , and either (with ) or (with and ).
nametypebuilderrequestscript_scriptIdfunction参考上方的Schema索引获取准确的字段Schema。
每个API至少需要:、,以及(包含)或(包含和)。
nametypebuilderrequestscript_scriptIdfunctionThe Response and Routing Model
响应与路由模型
Once the routers finish processing, the API selects which response to return and shapes its body. This is where APIs diverge most from flows -- the routing is narrower, and "mapping" happens at two distinct layers.
路由器完成处理后,API会选择要返回的响应并塑造其响应体。这是API与流程最大的不同之处——路由范围更窄,“映射”发生在两个不同的层级。
Branch selection and router chaining
分支选择与路由器链式调用
APIs support a single routing strategy: . Within a router, each record is evaluated against the branches in order and taken by the first branch whose matches; that record then follows only that branch. (Flows also offer , which fans one record out to every matching branch -- APIs never do this. A record takes exactly one branch per router.)
first_matching_branchinputFilterall_matching_branchesEach branch's decides where the record goes after that branch's page processors finish:
nextRouterId- Another router's -- chain into that router for a further stage of processing.
id - -- hand off to the response router (whose reserved
"apiRouter"is alwaysid) to finish.apiRouter
Chaining lets you express sequential stages where each stage branches independently; the last branch in the chain sets to reach the response router.
nextRouterId: "apiRouter"API仅支持一种路由策略:。在路由器内,每条记录会按顺序评估分支,被第一个匹配的分支接收;然后该记录仅沿该分支处理。(流程还支持,即一条记录会分发到所有匹配的分支——API从不使用这种方式。每条记录在每个路由器中仅走一个分支。)
first_matching_branchinputFilterall_matching_branches每个分支的决定记录在该分支的页面处理器完成后去向:
nextRouterId- 另一个路由器的——链接到该路由器进行下一阶段处理。
id - ——移交到响应路由器(其保留
"apiRouter"始终为id)以完成处理。apiRouter
链式调用可用于表达每个阶段独立分支的顺序处理;链中的最后一个分支设置以到达响应路由器。
nextRouterId: "apiRouter"Response selection -- success, fail, custom
响应选择——成功、失败、自定义
Every builder API has exactly one response, exactly one response, and zero or more responses (the response's field). The response router () picks one after processing completes:
successfailcustomtypeid: "apiRouter"- -- the happy path, returned when processing completed and no
successresponse matched. Conventionally a 2xxcustom(statusCode, or200when the API created something).201 - -- the error path. Processing errors (a lookup returned a 500, an import got a 4xx, a script threw) are routed here automatically. Conventionally a 4xx/5xx
fail(statusCodeor400); its500surface the error message and any context the caller needs.mappings - -- a non-error, non-default response selected by its own
custom. Reach for one when the outcome fits neitherinputFilternorsuccess, when thefaildiffers, or when the body shape differs. Typical cases:statusCode- not found -- the lookup ran but returned zero records (filter: the results array is empty).
404 - conflict -- the destination rejected a create because the record already exists.
409 - accepted -- processing started a background job; tell the caller "received, working on it."
202 - Conditional body -- a different shape driven by a query parameter (e.g. vs
?format=summary).?format=full
In mode the response router returns the first response whose matches, so list responses ahead of to let their specific conditions win. In mode a JavaScript function inspects the record and returns the response to use.
input_filtersinputFiltercustomsuccessscriptid每个构建器模式API有且仅有一个响应、一个响应,以及零个或多个响应(由响应的字段标识)。响应路由器()在处理完成后选择一个响应:
successfailcustomtypeid: "apiRouter"- ——正常路径,当处理完成且无匹配的
success响应时返回。通常使用2xx状态码(custom,或API创建资源时使用200)。201 - ——错误路径。处理错误(查询返回500、导入收到4xx、脚本抛出异常)会自动路由到此处。通常使用4xx/5xx状态码(
fail或400);其500会展示错误消息和调用者需要的上下文。mappings - ——非错误、非默认的响应,由自身的
custom选择。当结果既不属于inputFilter也不属于success、状态码不同或响应体格式不同时使用。典型场景:fail- 未找到——查询执行但未返回任何记录(过滤器:结果数组为空)。
404 - 冲突——目标系统因记录已存在而拒绝创建请求。
409 - 已接受——处理启动了后台任务;告知调用者“已接收,正在处理”。
202 - 条件响应体——由查询参数驱动的不同格式(例如vs
?format=summary)。?format=full
在模式下,响应路由器返回第一个匹配的响应,因此请将响应列在之前,使其特定条件优先匹配。在模式下,JavaScript函数检查记录并返回要使用的响应。
input_filtersinputFiltercustomsuccessscriptidstatusCode
vs the response type
statusCodetypestatusCode
与响应type
的区别
statusCodetypeThese are independent and often conflated:
- The response (
type/success/fail) is Celigo's internal classification -- it drives which response the response router selects.custom - The is the HTTP status the caller receives -- it lives on the response definition.
statusCode
A response can carry any (the "not found" response returns ; the "async accepted" response returns ), and is conventionally 2xx but doesn't have to be. So "return a when the customer isn't found" means adding a response with and an that matches when the lookup's results array is empty -- not editing the response.
customstatusCode404202success404customstatusCode: 404inputFiltersuccess两者相互独立,常被混淆:
- 响应****(
type/success/fail)是Celigo的内部分类——决定响应路由器选择哪个响应。custom - ****是调用者收到的HTTP状态码——定义在响应配置中。
statusCode
customstatusCode404202success404customstatusCode: 404inputFiltersuccessThe two mapping layers
两个映射层级
"Mapping" refers to two different things at two layers, and conflating them is the most common source of confusion when building APIs.
1. Page-processor (record enrichment). Configured on a lookup or import inside a router branch -- the same shape as a flow's page-processor . It pulls fields off that page processor's response and merges them onto the record so downstream routers, page processors, and response mappings can see them. It does not shape the HTTP body.
responseMappingresponseMapping{
"fields": [
{"extract": "id", "generate": "customerId"},
{"extract": "accountStatus", "generate": "status"}
]
}2. Response-stage (HTTP body). Configured on a / / response (alongside its and ). It reads the now-enriched record and builds the HTTP response body returned to the caller.
mappingssuccessfailcustomlookupshooks{
"mappings": [
{"extract": "customerId", "generate": "data.id"},
{"extract": "status", "generate": "data.status"}
]
}The two work together: the lookup's merges onto the record, then the response's place into the body's . A field the page processor returned must first be carried onto the record by a before a response can extract it. When unsure which layer you need, ask: does this step add the field to the record (page-processor ) or read the field off the record into the body (response )?
responseMappingcustomerIdmappingscustomerIddata.idresponseMappingmappingresponseMappingmappings“映射”指两个不同层级的不同操作,混淆两者是构建API时最常见的困惑来源。
1. 页面处理器(记录增强)。配置在路由器分支中的查询或导入上——与流程中页面处理器的格式相同。它从页面处理器的响应中提取字段,合并到记录中,供下游路由器、页面处理器和响应映射使用。它不塑造HTTP响应体。
responseMappingresponseMapping{
"fields": [
{"extract": "id", "generate": "customerId"},
{"extract": "accountStatus", "generate": "status"}
]
}2. 响应阶段(HTTP响应体)。配置在 / / 响应上(与和一起)。它读取已增强的记录,构建返回给调用者的HTTP响应体。
mappingssuccessfailcustomlookupshooks{
"mappings": [
{"extract": "customerId", "generate": "data.id"},
{"extract": "status", "generate": "data.status"}
]
}两者协同工作:查询的将合并到记录中,然后响应的将放入响应体的中。页面处理器返回的字段必须先通过添加到记录中,响应才能提取它。不确定需要哪个层级时,可问自己:此步骤是将字段添加到记录中(页面处理器)还是从记录中读取字段到响应体(响应)?
responseMappingcustomerIdmappingscustomerIddata.idresponseMappingmappingsresponseMappingmappingsCLI Commands
CLI命令
bash
undefinedbash
undefinedCRUD
CRUD操作
celigo apis list
celigo apis get <id>
celigo apis create < api.json
celigo apis update <id> < api.json
celigo apis set <id> key=value [key2=value2 ...]
celigo apis delete <id>
celigo apis list
celigo apis get <id>
celigo apis create < api.json
celigo apis update <id> < api.json
celigo apis set <id> key=value [key2=value2 ...]
celigo apis delete <id>
Clone (builder-mode only)
克隆(仅支持构建器模式)
celigo apis clone <id> --api-version <version> [--name <name>] [--description <desc>] [--environment <envId>]
celigo apis clone <id> --api-version <version> [--name <name>] [--description <desc>] [--environment <envId>]
Pipeline management
流水线管理
celigo apis add-processor <id> <exportOrImportId> [--router <routerId>] [--branch <branchName>]
celigo apis remove-processor <id> <exportOrImportId> [--router <routerId>] [--branch <branchName>]
celigo apis add-processor <id> <exportOrImportId> [--router <routerId>] [--branch <branchName>]
celigo apis remove-processor <id> <exportOrImportId> [--router <routerId>] [--branch <branchName>]
Logs
日志
celigo apis logs <id>
celigo apis log-detail <id> <key>
celigo apis logs <id>
celigo apis log-detail <id> <key>
Test run
测试运行
celigo apis test-run <id>
celigo apis test-run-step-results <id> <runId> <exportOrImportId>
celigo apis test-run-step-logs <id> <runId> <exportOrImportId>
celigo apis test-run <id>
celigo apis test-run-step-results <id> <runId> <exportOrImportId>
celigo apis test-run-step-logs <id> <runId> <exportOrImportId>
Debug (for exports/imports within the API pipeline)
调试(针对API流水线中的导出/导入)
celigo apis debug-requests <id> <exportOrImportId> [--since <minutes>]
celigo apis debug-request-detail <id> <exportOrImportId> <key>
celigo apis debug-requests <id> <exportOrImportId> [--since <minutes>]
celigo apis debug-request-detail <id> <exportOrImportId> <key>
Discovery
资源发现
celigo account search "<keyword>"
celigo templates marketplace
<!-- TIER:3 -->celigo account search "<keyword>"
celigo templates marketplace
<!-- TIER:3 -->Pre-Submit Checklist
提交前检查清单
Before creating or updating an API, verify:
- is set and descriptive
name - is
typeor"builder"(not omitted, which creates a legacy API)"script" - Builder mode: and
builder.request.methodare setbuilder.request.relativeURI - Builder mode: at least one router with at least one branch exists
- Builder mode: last branch has
nextRouterId: "apiRouter" - Builder mode: both and
successresponses are definedfail - Builder mode: success response uses
inputFilter["equals", ["boolean", ["context", "success"]], true] - Script mode: and
script._scriptIdreference a valid scriptscript.function - All and
_exportIdreferences in page processors point to existing resources_importId - Router IDs are unique within the API
- is set (it becomes part of the endpoint URL:
version)/{version}{relativeURI} - Input filter expressions wrap /
extractaccessors in type wrappers (context,string,number)boolean
创建或更新API前,请验证:
- 设置了且描述清晰
name - 设为
type或"builder"(不省略,否则会创建遗留API)"script" - 构建器模式:已设置和
builder.request.methodbuilder.request.relativeURI - 构建器模式:至少存在一个路由器和一个分支
- 构建器模式:最后一个分支设置了
nextRouterId: "apiRouter" - 构建器模式:已定义和
success响应fail - 构建器模式:成功响应的使用
inputFilter["equals", ["boolean", ["context", "success"]], true] - 脚本模式:和
script._scriptId引用有效的脚本script.function - 页面处理器中所有和
_exportId引用都指向现有资源_importId - 路由器ID在API内唯一
- 设置了(它会成为端点URL的一部分:
version)/{version}{relativeURI} - 输入过滤器表达式将/
extract访问器包裹在类型包装器(context、string、number)中boolean
Gotchas
常见陷阱
- PUT erases omitted fields. Always GET first, modify, then PUT. The command handles this automatically.
set - APIs only support routing. Unlike flows which also support
first_matching_branch, API routers always stop at the first matching branch.all_matching_branches - Omitting type wrappers silently fails. Use
inputFilter, not bare["boolean", ["context", "success"]]-- the filter will never match without the wrapper.["context", "success"] - Clone only works for builder-mode APIs. Script and legacy APIs cannot be cloned via the CLI.
- Missing a success or fail response causes undefined behavior. The response router won't know where to route.
- becomes part of the URL path.** The full endpoint is
**version. Changing the version changes the URL that callers must use./{version}{relativeURI} - Page-processor and response
responseMappingare different layers.mappingsenriches the record with fields from a page processor's response; a response'sresponseMappingshape the HTTP body from that record. A field the lookup returned won't reach the body unless amappingsfirst carries it onto the record.responseMapping - APIs don't start themselves. No , no listeners, no flow-level runtime controls, no abstract/instance templating. Scheduled or event-driven work belongs in a flow that calls the API.
schedule - returns 404 to callers. Use it to pause an API without deleting it; re-enable with
disabled: true.disabled: false
- PUT会删除未指定的字段。请始终先GET、修改,再PUT。命令会自动处理此问题。
set - API仅支持路由。与支持
first_matching_branch的流程不同,API路由器始终在第一个匹配分支处停止。all_matching_branches - 省略inputFilter类型包装器会导致静默失败。请使用,而非直接使用
["boolean", ["context", "success"]]——没有包装器的过滤器永远不会匹配。["context", "success"] - 克隆仅适用于构建器模式API。脚本和遗留API无法通过CLI克隆。
- 缺少success或fail响应会导致未定义行为。响应路由器不知道该路由到哪里。
- 会成为URL路径的一部分。完整端点为
version。修改版本会改变调用者必须使用的URL。/{version}{relativeURI} - 页面处理器和响应
responseMapping是不同层级。mappings用页面处理器响应中的字段增强记录;响应的responseMapping从该记录塑造HTTP响应体。查询返回的字段必须先通过mappings添加到记录中,才能被响应responseMapping提取。mappings - API无法自行启动。没有、监听器、流程级运行时控制项、抽象/实例模板。定时或事件驱动的工作属于调用API的流程。
schedule - 会向调用者返回404。使用它暂停API而无需删除;设置
disabled: true重新启用。disabled: false
Common Errors
常见错误
| Error | Cause | Fix |
|---|---|---|
| Wrong | Verify the full URL is |
| Missing required fields or invalid field values | Check the Pre-Submit Checklist; verify |
Response always returns the | Success | Use |
| Response body is empty | Response | Verify mapping extract paths match the actual processed record structure |
| Pipeline step silently skipped | | Debug with |
| Attempting to clone a script-mode or legacy API | Clone is builder-mode only; recreate script APIs manually |
| Page processor returns no data | Export/import | Verify the referenced resource exists and is enabled with |
| | Ensure all |
| Response body missing a field the lookup returned | The page-processor | Add a |
| 错误 | 原因 | 修复方法 |
|---|---|---|
API端点返回 | 请求中的 | 验证完整URL为 |
创建/更新时返回 | 缺少必填字段或字段值无效 | 检查提交前检查清单;验证 |
响应始终返回 | 成功响应的 | 严格使用 |
| 响应体为空 | 未配置响应 | 验证映射提取路径与实际处理后的记录结构匹配 |
| 流水线步骤被静默跳过 | 分支上的 | 使用 |
出现 | 尝试克隆脚本模式或遗留API | 克隆仅支持构建器模式;手动重新创建脚本API |
| 页面处理器未返回数据 | 导出/导入的 | 使用 |
出现 | | 确保所有 |
| 响应体缺少查询返回的字段 | 页面处理器的 | 在页面处理器上添加 |