<!-- TIER:1 -->
Building APIs
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 and (use for single results). For imports the response is via (use )
- postResponseMap hook -- JavaScript processing after response mapping, configured on entries
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.
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.
- 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 (, , 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.
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.
API Modes
Builder Mode ()
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, mappings
The incoming HTTP request replaces the export as data source. Routers and page processors work identically to flows.
API Execution Pipeline (Builder Mode)
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
- 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
- Response router -- (id="apiRouter") selects which response template to use based on response input filters
- Response -- selected response template returned to the caller with its statusCode, headers, and body
Script Mode ()
A single
JavaScript function receives the request object (method, headers, queryParams, body, pathParams) and returns
{statusCode, headers, body}
. Complete control with no visual configuration.
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.
Quick 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 | can implement arbitrary logic |
| 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 |
Minimum Required Fields
| Mode | Required Fields |
|---|
| Builder | , , (method + relativeURI) |
| Script | , , , |
| Legacy | , , (no field) |
Schema Index
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 |
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), / hooks, and
- 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
<!-- TIER:2 -->
How to Build an API
1. Plan what the API needs to do
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
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).
3. Check for existing resources
Look for connections, exports, and imports that can be reused before creating new ones.
bash
# Search across all resource types in the account
celigo account search "<keyword>"
# Show what an existing API uses (exports, imports, connections)
celigo account dependencies api <id>
# Find orphaned resources that could be reused
celigo account lint
# Search for APIs already in the account for patterns
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>"
# Search marketplace for pre-built integration templates
celigo templates marketplace
The account index auto-refreshes when stale (>4 hours). Force a fresh snapshot with
.
4. Create the supporting resources (bottom-up)
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)
- Imports -- for writes to external systems (use skill)
5. Define the request (builder mode)
Choose the HTTP method and URI path. GET and POST are most common; PUT and PATCH are rare.
- Path parameters use colon notation:
- Document query parameters, path parameters, headers, and body schema
- Add a for testing the pipeline without live calls
- Optionally add a request (expression-based or script-based) to reshape incoming data before processing
6. Build the processing pipeline
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.
Input filters use s-expression syntax:
["operator", ["type", ["extract", "field"]], value]
. Type wrappers (
,
,
) are required around
and
accessors. Logical combinators:
,
.
The last branch in the chain must set
nextRouterId: "apiRouter"
to reach the response router.
7. Configure responses
Every builder API needs exactly one
response and one
response. Add
responses for specific scenarios (e.g., 404 not found, 422 validation error).
Each response has:
- (HTTP status code)
- to determine when it's selected (typically
["equals", ["boolean", ["context", "success"]], true]
for success)
- to shape the response body from the processed record
- Optional for documentation, , , and (preMap, postMap)
8. Configure the response router
Set
and choose routing method:
- (default) -- evaluates each response's
- -- custom JavaScript returns the response to use
9. Build the JSON
Reference the
Schema Index above for exact field schemas.
Every API needs at minimum:
,
, and either
(with
) or
(with
and
).
The 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.
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.)
Each branch's
decides where the record goes after that branch's page processors finish:
- Another router's -- chain into that router for a further stage of processing.
- -- hand off to the response router (whose reserved is always ) to finish.
Chaining lets you express sequential stages where each stage branches independently; the last branch in the chain sets
nextRouterId: "apiRouter"
to reach the response router.
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:
- -- the happy path, returned when processing completed and no response matched. Conventionally a 2xx (, or when the API created something).
- -- 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 ( or ); its surface the error message and any context the caller needs.
- -- a non-error, non-default response selected by its own . Reach for one when the outcome fits neither nor , when the differs, or when the body shape differs. Typical cases:
- not found -- the lookup ran but returned zero records (filter: the results array is empty).
- conflict -- the destination rejected a create because the record already exists.
- accepted -- processing started a background job; tell the caller "received, working on it."
- Conditional body -- a different shape driven by a query parameter (e.g. vs ).
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.
vs the response
These are independent and often conflated:
- The response ( / / ) is Celigo's internal classification -- it drives which response the response router selects.
- The is the HTTP status the caller receives -- it lives on the response definition.
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.
The 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.
{
"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.
{
"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
)?
CLI Commands
bash
# 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>
# Clone (builder-mode only)
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>]
# Logs
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>
# Debug (for exports/imports within the API pipeline)
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 -->
Pre-Submit Checklist
Before creating or updating an API, verify:
Gotchas
- PUT erases omitted fields. Always GET first, modify, then PUT. The command handles this automatically.
- APIs only support routing. Unlike flows which also support , API routers always stop at the first matching branch.
- Omitting type wrappers silently fails. Use
["boolean", ["context", "success"]]
, not bare -- the filter will never match without the wrapper.
- 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 . Changing the version changes the URL that callers must use.
- Page-processor and response are different layers. enriches the record with fields from a page processor's response; a response's shape the HTTP body from that record. A field the lookup returned won't reach the body unless a first carries it onto the record.
- 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.
- returns 404 to callers. Use it to pause an API without deleting it; re-enable with .
Common Errors
| Error | Cause | Fix |
|---|
| on API endpoint | Wrong or in the request | Verify the full URL is and both match the API definition |
| validation error on create/update | Missing required fields or invalid field values | Check the Pre-Submit Checklist; verify is set |
| Response always returns the response | Success is malformed or missing type wrapper | Use ["equals", ["boolean", ["context", "success"]], true]
exactly |
| Response body is empty | Response not configured or field paths don't match | Verify mapping extract paths match the actual processed record structure |
| Pipeline step silently skipped | on a branch evaluates to false for all records | Debug with celigo apis test-run-step-results
to see each step's input/output |
| error | 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 reference is wrong or resource is disabled | Verify the referenced resource exists and is enabled with / |
| error | references a non-existent router ID | Ensure all values match a real router or |
| Response body missing a field the lookup returned | The page-processor never carried the field onto the record | Add a entry ({"fields": [{"extract": ..., "generate": ...}]}
) on the page processor so the response have it to extract |