Carry out an action after approval and read it back
An operations hub does not only read data; it also acts: changing a price, delisting a product, adjusting a budget. This recipe sets the rule for acting: agents never operate a back office directly; they file action requests. A workflow first sends an approval task; after you approve, a script that does only that one thing carries it out, reads the back office again to confirm the change, and records the result in an action table. It is layer ⑤ of the business operations hub.
In the Develop run on this page the “back office” is a listings table in the same database and the action is changing one product’s price. For your back office, replace only the “carry out” and “read back” steps in the action script: call the back office’s own price and lookup endpoints from the signed-in page, as in the sync recipe.
Prerequisites
- The database
DBfrom the sync recipe, and itsapifunction. - The approver’s user id (
usr_…), asAPPROVER.
1. Create the action table and the stand-in back office
api /database/v1/table/$DB/tables --data '{"name":"actions","fields":[ {"name":"request_id","type":"string","required":true,"unique":true}, {"name":"sku","type":"string"},{"name":"field","type":"string"}, {"name":"before","type":"number"},{"name":"after","type":"number"}, {"name":"approved_by","type":"string"},{"name":"status","type":"string"}, {"name":"executed_at","type":"datetime","indexed":true}]}' | jq -e '.name == "actions"'api /database/v1/table/$DB/tables --data '{"name":"listings","fields":[ {"name":"sku","type":"string","required":true,"unique":true},{"name":"price","type":"number","required":true}]}' | jq -e '.name == "listings"'api /database/v1/table/$DB/rest/listings --data '{"sku":"RING-001","price":1299}'actions.request_id is the unique key: one id per request, and an id is carried out once.
2. Write the action script
Save as apply-price.ts. One script does one action, in five steps: check whether this request already ran → record the value before → carry out → read back → record in the action table.
type Input = { database_id: string; request_id: string; // one id per request: an id is carried out once sku: string; price: number; approved_by: string;};
export default async (input: Input): Promise<{ status: string; before: number | null; after: number | null }> => { const db = (table: string) => ({ database_id: input.database_id, table }); const rows = (r: unknown) => r as Array<Record<string, unknown>>;
// 1. If this request id already ran, return that result instead of changing anything twice. const done = rows(await praxis.database.table.rest.retrieve({ path: db("actions"), query: { request_id: `eq.${input.request_id}` } })); if (done.length > 0) return { status: `already ${done[0].status}`, before: done[0].before as number, after: done[0].after as number };
// 2. Record the value before the change. const read = async () => rows(await praxis.database.table.rest.retrieve({ path: db("listings"), query: { sku: `eq.${input.sku}` } }))[0]; const before = (await read())?.price as number | undefined; if (before === undefined) throw new Error(`no listing ${input.sku}`);
// 3. Carry out this one action. In a real back office this calls its own price endpoint from the signed-in page; here the back office is the listings table. await praxis.database.table.rest.update({ path: db("listings"), query: { sku: `eq.${input.sku}` }, body: { price: input.price } });
// 4. Read back: read the back office again and confirm the change. const after = (await read())?.price as number; const status = after === input.price ? "done" : "mismatch";
// 5. Record in the action table: who approved, before and after, the read-back result. await praxis.database.table.rest.create({ path: db("actions"), body: { request_id: input.request_id, sku: input.sku, field: "price", before, after, approved_by: input.approved_by, status, executed_at: new Date().toISOString() }, }); if (status !== "done") throw new Error(`read-back ${after} != requested ${input.price}`); return { status, before, after };};When the read-back does not match, the script records a mismatch row and fails the run instead of reporting success.
3. Write the approval workflow
Save as approve-price.yaml. The first step sends the approval task and waits; only an approval runs the action script, and a rejection or timeout ends the run.
document: { dsl: "1.0.3", namespace: ops-hub, name: approve-price, version: "1.0.0" }do: - ask: call: praxis/approval with: title: '${ "Price change: " + .sku + " → " + (.price | tostring) }' body: '${ "Analyst reason: " + .reason }' context: '${ { sku: .sku, price: .price, request_id: .request_id } }' assignees: users: '${ [ .approver ] }' allow_self_approval: true due: P1D on_timeout: { action: reject } - decide: switch: - approved: when: '${ .decision == "approve" }' then: apply - otherwise: then: end - apply: run: script: namespace: ops-hub name: apply-price version: "1.0.0" input: database_id: '${ $workflow.input.database_id }' request_id: '${ $workflow.input.request_id }' sku: '${ $workflow.input.sku }' price: '${ $workflow.input.price }' approved_by: '${ .decided_by.id }'allow_self_approval: true is only so that one person can walk through this page; remove it in real use, so whoever starts a run cannot approve their own request. By default the task is rejected when nobody decides within a day (on_timeout).
4. Publish and file a request
api /automation/v1/scripts --data "$(jq -n --rawfile s apply-price.ts '{namespace:"ops-hub",name:"apply-price",draft:{source:$s}}')" > /dev/nullREV=$(api /automation/v1/scripts/ops-hub/apply-price | jq -er .draft.revision)api /automation/v1/scripts/ops-hub/apply-price/versions --data "{\"version\":\"1.0.0\",\"draft\":{\"revision\":\"$REV\"}}" | jq -e .versionapi /automation/v1/workflows --data "$(jq -n --rawfile s approve-price.yaml '{namespace:"ops-hub",name:"approve-price",draft:{source:$s}}')" > /dev/nullREV=$(api /automation/v1/workflows/ops-hub/approve-price | jq -er .draft.revision)api /automation/v1/workflows/ops-hub/approve-price/versions --data "{\"version\":\"1.0.0\",\"draft\":{\"revision\":\"$REV\"}}" | jq -e .versionRUN=$(api /automation/v1/runs --data "$(jq -n --arg db "$DB" --arg who "$APPROVER" '{ target:"ops-hub/approve-price@1.0.0", deadline_seconds:172800, input:{database_id:$db, request_id:"req-ring-001-20261125", sku:"RING-001", price:1199, reason:"Conversion over the last 7 days is below similar products; suggest cutting the price by 100 for a week.", approver:$who}}')" | jq -er .id)api /automation/v1/runs/$RUN | jq .statusExpected: status is waiting, and the approver sees the task in their Console to-dos or in the approval task list. When the analyst finds a problem, it starts this run with the same input.
5. Approve, then check
The approver clicks Approve in the Console, or submits through the API:
TASK=$(api /automation/v1/human-tasks | jq -er '[.data[] | select(.status == "open")][0].id')api /automation/v1/human-tasks/$TASK/respond --data '{"action_id":"approve","comment":"Approved, try it for a week"}' | jq .statusuntil [[ "$(api /automation/v1/runs/$RUN | jq -r .status)" =~ ^(completed|faulted|cancelled)$ ]]; do sleep 5; doneapi /automation/v1/runs/$RUN | jq '{status, output}'api "/database/v1/table/$DB/rest/actions?select=request_id,before,after,approved_by,status"Expected: the run is completed with output {"status":"done","before":1299,"after":1199}; the action table has one row with the approver and the values before and after.
Common mistakes
| Symptom | Cause and fix |
|---|---|
| A request is carried out twice | The action script does not check request_id first, or request_id is not the action table’s unique key |
The script fails with rest.list does not exist | Rows are read with praxis.database.table.rest.retrieve |
| The task was sent to you but you cannot approve it | By default you cannot approve a request you started; this page uses allow_self_approval: true for the walkthrough, remove it in real use |
The run stays waiting | Nobody decided. A timeout ends it per on_timeout; for longer, raise due and keep deadline_seconds above it |
| Updating a draft returns a missing-revision error | Updating a script or workflow draft needs the draft.revision you read in the body; after publishing a new version, move the trigger or the workflow reference to it |
Run record
2026-11-25, Develop. Stand-in back office: the listings table, product RING-001 priced 1299. The workflow used the Chinese task title.
| Item | Result |
|---|---|
| File the request | the run went waiting and the task “改价:RING-001 → 1199” reached the approver’s to-dos |
| Approve | the run completed with done, before 1299, after 1199; listings read back 1199; one actions row with the approver in approved_by |
| Same request again (price 999), approved | output already done; price still 1199, still one action row |
| A new request, rejected | the run completed with decision: reject; nothing ran, price and action table unchanged |
| Records | database db_53906c278792437a, script ops-hub/apply-price@1.0.0, workflow ops-hub/approve-price@1.0.0 |
Next steps
For each new action, write one action script that does only that thing and one workflow that sends the approval; do not write one general script that can change anything. The whole solution is the business operations hub, and a real deployment is the Douyin store operations hub.