Skip to content

Node-RED

The OnERP nodes for Node-RED read and write business objects and run actions and functions from a flow. OnERP does not push events to Node-RED, so a flow starts on Node-RED’s side (an inject node, a schedule, MQTT, http in) and then talks to OnERP.

The nodes are built from the OnERP source repository; they are not published to the Node-RED library. From the repository root:

pnpm turbo build --filter=@onerp/node-red
pnpm --filter @onerp/node-red deploy --prod --legacy /tmp/onerp-node-red
cd ~/.node-red && npm install /tmp/onerp-node-red

Restart Node-RED. The onerp read, onerp write and onerp call nodes appear in the palette.

Every OnERP node points at an onerp-config node holding the server’s address (for example https://erp.example.com) and an API key from a service account. The account’s roles decide what the flows may do. The key is kept in Node-RED’s encrypted credentials, not in an exported flow.

The connection signs in and loads the workspace’s definitions when the flow is deployed. A wrong address or key shows at once as a red status on the nodes. A kind of business object added to OnERP later becomes visible to the flows after the next deploy.

The node’s settings name the kind of business object (such as sales/SalesOrder), the mode and the operation; the data rides on the message. Business objects arrive as plain JSON, with decimals and dates as strings.

onerp read

Mode Takes Returns in msg.payload
get msg.id The business object, or null when there is none
list msg.payload, optional: { filter, sort, cursor, limit, withTotal } { items, nextCursor, total }. Pass nextCursor back as cursor for the next page

onerp write

Mode Takes Returns in msg.payload
create msg.payload, the new business object The created business object, active
update msg.id, and msg.payload with the fields to change The changed business object
delete msg.id msg.payload unchanged

onerp call

Target Takes Returns in msg.payload
A function: Operation is namespace/name, Business Object empty msg.payload, the parameters The result, or null
An action: Business Object set, Operation is the action’s name msg.id, and msg.payload with the parameters The result, or null

The filter and business object shapes are those of the HTTP API.

A failed request goes down the node’s error path, so a catch node handles it like any other flow error. When OnERP refused the request, the message also carries its error:

{ "onerpError": { "code": "core.forbidden", "status": 403, "detail": "…" } }

The codes are listed under HTTP conventions. The node’s status shows ok in green after a success, or the error in red.

The nodes never retry, and each write is sent with a new idempotency key, so retrying a failed write from the flow may write twice. Updates are not conditional on a revision.