Goal of this module
When plain CRUD isn't enough, a logic block is a multi-step pipeline you compose from steps and expose as one endpoint. You'll build complete-task and call it from the app gateway.
What a logic block is
A logic block is an ordered array of steps. The execution engine runs them in sequence at request time, passing data between them with {{...}} references. Like everything else, it's configuration — not deployed code. Reach for one when you need to touch several entities, branch, loop, call AI, or hit an external system in a single named endpoint.
The steps you'll use
- get_entity — fetch the task by id.
- formula — compute the completion timestamp (
NOW()). - update_entity — set
statusandcompleted_at.
1 · Define complete-task
You build logic block definitions in API Studio (CRUD on config records). The block takes a task id as a path parameter and runs three steps.
POST /api/complete-task/custom
{
"apiName": "complete-task",
"inputSchema": { "pathParams": [{ "name": "pathid", "required": true }] },
"steps": [
{ "id": "s1", "type": "get_entity", "outputAs": "task",
"config": { "apiName": "task", "inputValue": "{{input.pathid}}" } },
{ "id": "s2", "type": "formula", "outputAs": "now",
"config": { "expressions": [ { "name": "now", "formula": "NOW()" } ] } },
{ "id": "s3", "type": "update_entity", "outputAs": "updated",
"config": { "apiName": "task", "inputValue": "{{input.pathid}}",
"data": { "status": "done", "completed_at": "{{now}}" } } }
]
} AI Design — generate a draft
You can describe a workflow in natural language and have AI Design (POST /api/custom/ai-generate) draft the step definitions for you. Treat the output as a first draft to review and refine — it's a build-time tool, not a runtime feature.
completed_at field
If you didn't add completed_at to the Task entity in Module 2, add it now as a string field — update_entity can only set fields the entity declares.
2 · Run it
Your app runs logic blocks on the app gateway. The greedy {pathid+} suffix carries the task id.
POST /app/{orgCode}/logicblocks/complete-task/{taskId} curl -X POST \
https://{domain}.nostackai.com/app/{orgCode}/logicblocks/complete-task/<taskId> \
-H 'Authorization: <app-token>'
# -> 200 { "updated": { "id": "<taskId>", "status": "done" } } Guarded by ACL too
Logic blocks run behind the same app authorizer. complete-task performs an update, so the caller needs an Allow for the update action — your task-editor from Module 4 covers it; a viewer would be denied.
Try it
Build complete-task, then call it on one of your todo tasks. Confirm with GET /app/{orgCode}/item/task/{id} that status is now done and completed_at is set. This simple version always re-stamps both fields — it doesn't guard against re-completing an already-done task; add a condition step checking task.status first if you want that guard.