How-to guides
Build a custom API with flows
Included free on every install. A custom path, other protocols and the outbound nodes require a license with the
flow-profeature. See pricing.
Your frontend wants every open order with its customer and its shipments in
one call. This guide builds that endpoint as a flow:
GET /api/v1/flows/orders-with-customer, reading three content types. You test
it against real entries before it goes live, cache the answer for 30 seconds,
allow each caller 120 calls a minute, call it with an API key, and export it as
a file you can import anywhere. Everything here runs on the free tier, and
every step works in LyEve Console or with the API.
Before you start
Link to the section Before you start- A running instance. The quickstart starts one and creates the first administrator.
- For the console steps, the console signed in as that administrator.
- For the API steps,
curl,jqand an admin token inTOKEN. Sign in shows how to get one. - Admin calls go to the Admin API on port
3001, and the finished endpoint is served by the Content API on port3002. See the two APIs.
1. Create the three content types
Link to the section 1. Create the three content typesAn order belongs to a customer, and a shipment belongs to an order.
Console v0.28.0
- Open Schema builder and choose New schema. Enter
Customerin Display name andcustomersin Machine name. - Choose Add field, name it
name, keep the typetextand tick Req. Choose Add field again, name itemailand pick the typeemail. Choose Save. - Choose New schema for
Order, machine nameorders. Choose Add relation and name the fieldcustomer. Under Relation, keep Belongs to one, pick Customer in Target schema and tick Req. - Add a
textfield namedstateand tick Idx, then anumberfield namedtotal. Choose Save. - Choose New schema for
Shipment, machine nameshipments. Add a relation namedorderthat belongs to one Order, with Req ticked, then twotextfields,carrierandtracking_number. Choose Save.
The schema builder in console v0.25.0 has no switch for a unique field, so
email is not unique on this path. Nothing below depends on it.
Engine API v0.62.0
curl -X POST http://localhost:3001/api/admin/schemas \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"name": "customers", "display_name": "Customer", "fields": [ {"name": "name", "field_type": "text", "required": true}, {"name": "email", "field_type": "email", "unique": true}]}'
curl -X POST http://localhost:3001/api/admin/schemas \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"name": "orders", "display_name": "Order", "fields": [ {"name": "customer", "field_type": "relation", "relation_to": "customers", "relation_type": "belongs_to", "required": true}, {"name": "state", "field_type": "text", "indexed": true}, {"name": "total", "field_type": "number"}]}'
curl -X POST http://localhost:3001/api/admin/schemas \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"name": "shipments", "display_name": "Shipment", "fields": [ {"name": "order", "field_type": "relation", "relation_to": "orders", "relation_type": "belongs_to", "required": true}, {"name": "carrier", "field_type": "text"}, {"name": "tracking_number", "field_type": "text"}]}'Each call answers 200 with the content type as stored.
The customer relation gives every order a customer_id field, and order
gives every shipment an order_id field. The flow reads those two fields.
Data model explains relations.
2. Add a customer, an order and a shipment
Link to the section 2. Add a customer, an order and a shipmentThe test run in step 5 needs entries to return.
Console v0.28.0
- Open Content, pick Customer and choose New entry. Enter
Ada Lovelacein Name andada@example.comin Email, then choose Create. - Pick Order and choose New entry. In Customer, type
Adaand pick the customer. Enteropenin State and42in Total, then choose Create. - Pick Shipment and choose New entry. Choose Order and pick the
order. An order has no title field, so the picker lists it as
Untitled entry. EnterDHLin Carrier andJD0001in Tracking number, then choose Create.
Engine API v0.62.0
CUSTOMER_ID=$(curl -s -X POST http://localhost:3002/api/v1/content/customers \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"data": {"name": "Ada Lovelace", "email": "ada@example.com"}}' | jq -r .id)
ORDER_ID=$(curl -s -X POST http://localhost:3002/api/v1/content/orders \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"data": {"customer_id": "'"$CUSTOMER_ID"'", "state": "open", "total": 42}}' | jq -r .id)
curl -X POST http://localhost:3002/api/v1/content/shipments \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"data": {"order_id": "'"$ORDER_ID"'", "carrier": "DHL", "tracking_number": "JD0001"}}'The last call answers 201 with the shipment, its order_id set to the order.
3. Create the account that publishes the flow
Link to the section 3. Create the account that publishes the flowThe flow's content nodes read as the account that publishes it, and a test
run reads as the account that runs it. The first administrator is a super
admin, and no access rule limits a super admin. To hold the flow to the rules,
create an admin of the tenant for the flow, and let the admin role read the three
content types. A free install holds three accounts with an admin role, the
first administrator included.
Console v0.28.0
- Open Access > Users and choose New user. Enter
flows@example.comin Email and a password in Password. Under Roles, untick editor and tick admin, then choose Create. - Open Access > Permissions and choose Add a content type rule for admin.
Pick
customersin Resource, tick Read and choose Create. Do the same forordersandshipments. - Sign out, and sign in again as
flows@example.com.
Engine API v0.62.0
curl -X POST http://localhost:3001/api/admin/users \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"email": "flows@example.com", "password": "Flows-Publisher-2026", "roles": ["admin"]}'
for type in customers orders shipments; do curl -X POST http://localhost:3001/api/admin/permissions \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"role": "admin", "schema_name": "'"$type"'", "actions": ["read"]}'doneThe user call answers 201 and each rule 200. Sign in as the new account
and keep its token in TOKEN for the rest of the guide:
curl -X POST http://localhost:3001/api/admin/auth/login \ -H "Content-Type: application/json" \ -d '{"email": "flows@example.com", "password": "Flows-Publisher-2026"}'
export TOKEN="<the token from the answer>"Access rules explains how rules combine.
4. Create the flow
Link to the section 4. Create the flowThe flow has an HTTP trigger and four nodes:
| Node | Type | What it does |
|---|---|---|
orders | content.query | Lists orders whose state is ?state= from the URL, or open. populate embeds each order's customer. |
shipments | content.query | Lists the shipments of every loaded order in one query. A list in filters matches any of its values, and map(input, .id) is the list of order ids. |
join | data.join | Attaches each order's shipments to it as shipments. how: left keeps orders that have none yet. |
respond | response | Answers the caller with the joined list. |
The edge from orders to shipments is what lets shipments read the orders
as its input: a node can read only what reaches it through an edge.
Save the definition as orders-with-customer.json:
{ "version": 1, "name": "Orders with customer and shipments", "slug": "orders-with-customer", "trigger": { "type": "trigger.http", "config": { "method": "GET", "auth": "auth" } }, "nodes": [ { "id": "orders", "type": "content.query", "position": { "x": 120, "y": 200 }, "config": { "schema": "orders", "filters": { "state": "{{ trigger.query.state ?? \"open\" }}" }, "populate": ["customer"], "limit": 100, "sort": "-created_at" } }, { "id": "shipments", "type": "content.query", "position": { "x": 420, "y": 420 }, "config": { "schema": "shipments", "filters": { "order_id": "{{ map(input, .id) }}" } } }, { "id": "join", "type": "data.join", "position": { "x": 420, "y": 300 }, "config": { "left_key": "id", "right_key": "order_id", "how": "left", "as": "shipments", "many": true } }, { "id": "respond", "type": "response", "position": { "x": 720, "y": 300 }, "config": { "status": 200, "body": "{{ input }}" } } ], "edges": [ { "from": "orders", "to": "shipments" }, { "from": "orders", "to": "join", "to_port": "left" }, { "from": "shipments", "to": "join", "to_port": "right" }, { "from": "join", "to": "respond" } ]}Then import it as a draft.
Console v0.28.0
Open Flows and choose Import. Upload orders-with-customer.json under
Definition file, keep Create a new flow and choose Import. The
editor opens on the draft, with the four nodes drawn on the canvas.
Engine API v0.62.0
curl -X POST http://localhost:3001/api/admin/flows/import \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d @orders-with-customer.jsonThe answer is 201 with the flow, "status": "draft", "version": 0 and
"unresolved_datasources": []. Copy its id into FLOW_ID. The flow now
appears under Flows in the console, drawn on the canvas.
5. Test it
Link to the section 5. Test itA test run executes the draft against a trigger payload you supply. Nothing is published.
Console v0.28.0
On the Test tab below the canvas, add "query": {"state": "open"} to the
JSON in Trigger and choose Run test. The run reads succeeded, with
the steps trigger, orders, shipments, join and respond listed beside
it. Choose a step to see what went in and what came out.
Engine API v0.62.0
curl -X POST http://localhost:3001/api/admin/flows/$FLOW_ID/test \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"trigger": {"query": {"state": "open"}}}'The answer is the run, with the response body under output and one entry per
step. Trimmed, it looks like this:
{ "status": "succeeded", "is_test": true, "output": [ { "id": "abab67c8-e941-4fb3-8d43-25bd70e46025", "state": "open", "total": 42, "customer_id": "e3b09dae-3674-4cf6-8a55-2f4a2b7df61c", "customer": { "id": "e3b09dae-3674-4cf6-8a55-2f4a2b7df61c", "name": "Ada Lovelace", "email": "ada@example.com" }, "shipments": [ { "id": "2f460c41-14b5-49f4-a433-7b2dd0f9162f", "order_id": "abab67c8-e941-4fb3-8d43-25bd70e46025", "carrier": "DHL", "tracking_number": "JD0001" } ] } ], "steps": [ { "node_id": "trigger", "node_type": "trigger.http", "status": "succeeded" }, { "node_id": "orders", "node_type": "content.query", "status": "succeeded" }, { "node_id": "shipments", "node_type": "content.query", "status": "succeeded" }, { "node_id": "join", "node_type": "data.join", "status": "succeeded" }, { "node_id": "respond", "node_type": "response", "status": "succeeded" } ]}Each step also carries its input, output, error and duration_ms.
6. Add a cache and a rate limit
Link to the section 6. Add a cache and a rate limitBoth live on the trigger.
Console v0.28.0
Choose the API request node. In the Inspector, under Cache, enter
30s in ttl. Under Rate limit, enter 120 in requests and 1m
in per. Choose Save.
Engine API v0.62.0
This reads the draft, adds them, and saves it back:
curl -s http://localhost:3001/api/admin/flows/$FLOW_ID \ -H "Authorization: Bearer $TOKEN" \ | jq '{definition: (.draft | .trigger.config += { cache: {ttl: "30s"}, rate_limit: {requests: 120, per: "1m"}})}' \ | curl -X PUT http://localhost:3001/api/admin/flows/$FLOW_ID \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d @-The answer is 200 with the saved draft.
The cache keeps each answer for 30 seconds, one entry per URL and caller, so
?state=open and ?state=paid never share one. The rate limit gives each
caller 120 calls a minute. To key either one on something else, add a key
expression, as
Limit and cache an endpoint
explains.
7. Publish
Link to the section 7. PublishConsole v0.28.0
Choose Publish. The badge beside the slug reads Published v1.
Engine API v0.62.0
curl -X POST http://localhost:3001/api/admin/flows/$FLOW_ID/publish \ -H "Authorization: Bearer $TOKEN"The answer is 200 with "status": "active" and "version": 1.
Later saves change only the draft, so the endpoint keeps serving version 1 until you publish again.
8. Create an API key for the frontend
Link to the section 8. Create an API key for the frontendA key that calls flows needs the flows:read scope.
Console v0.28.0
The API keys page is open to a super admin, so sign in again as the first administrator.
- Open Access > API keys and choose New key.
- Enter
orders-frontendin Name. - Under Content, untick Read. Open Flows and tick Read. The summary
below the sections reads
1 scope: flows:read. - Choose Create.
The dialog shows the key once. Copy it into API_KEY for the next step.
Engine API v0.62.0
curl -X POST http://localhost:3001/api/admin/api-keys \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"name": "orders-frontend", "scopes": ["flows:read"]}'The answer is 201 and carries the key once, as raw_key. Copy it into
API_KEY.
See API keys for scopes and expiry.
9. Call your endpoint
Link to the section 9. Call your endpointThis step is the same on both paths:
curl -i "http://localhost:3002/api/v1/flows/orders-with-customer?state=open" \ -H "X-API-Key: $API_KEY"HTTP/1.1 200 OKContent-Type: application/jsonRatelimit-Limit: 120Ratelimit-Remaining: 119Ratelimit-Reset: 1790917634X-Flow-Cache: missThe body is the same list the test returned. Send the call again within 30
seconds and X-Flow-Cache says hit: the flow did not run. Past 120 calls in
a minute, a call answers 429 with a Retry-After header. A call with no credentials
answers 401.
10. Export it and import a copy
Link to the section 10. Export it and import a copyDownload the flow as YAML, then import it as a new draft under another slug.
Console v0.28.0
- Open the flow, choose More actions (the
...button beside Flows) and then Export. Pick YAML and choose Download YAML. - In the downloaded
orders-with-customer.yaml, change the lineslug: orders-with-customertoslug: orders-v2. The import dialog has no slug field of its own. - Open Flows, choose Import, upload the file and choose Import.
The editor opens on orders-v2 as a draft.
Engine API v0.62.0
curl "http://localhost:3001/api/admin/flows/$FLOW_ID/export?format=yaml" \ -H "Authorization: Bearer $TOKEN" -o orders-with-customer.yaml
curl -X POST "http://localhost:3001/api/admin/flows/import?mode=create&slug=orders-v2" \ -H "Authorization: Bearer $TOKEN" \ -F "file=@orders-with-customer.yaml"The import answers 201 with the new flow as a draft, and
"unresolved_datasources": [], because this flow uses no saved connection.
The same file imports into another instance, which is how you promote a flow
from staging to production. To import into another tenant of this instance,
send the import as a super admin with X-Tenant-ID naming that tenant, as
Tenants explains. See
Move flows between tenants and instances.
- Flow templates: eighteen starter flows, among them a
larger version of this one. It filters on a
statusfield, so change itsordersfilter tostateto run it on the types from this guide. - Keep the content model and flows in git: review flow files in pull requests and promote them on release.
- Flows: serve the endpoint at a
path of your own, or over GraphQL, gRPC and realtime, with
flow-pro. - Flow definition format: every node, its settings and the expression language.