Skip to main content

Dispatch a POS webhook to sub-workflows

This workflow receives the events sent by a point-of-sale software through an API route, identifies the resource targeted by the request, then delegates the processing to a dedicated sub-workflow (order, payment or refund).

Loading the diagram…

The need​

A point-of-sale software sends its events (orders, payments, refunds) through an API route. Each event must be dispatched to the dedicated sub-workflow based on the request method and route, so that each type of event is handled by a dedicated process.

What the workflow does​

  1. POS webhook — the API route trigger receives the notifications from the POS software. The path /v1/pos/*path captures the resource (orders, payments, refunds) in incomingRequest.params.path; the HTTP method arrives in incomingRequest.method and the request body in data.
  2. Identify the resource — the Code node combines the method and the path into context.variables.route (e.g. POST orders).
  3. Request resource — the Switch node routes {{ context.variables.route }} to the matching branch.
  4. Sub-workflow: register the order — for POST orders, the Call a workflow node runs the POS — Register an order sub-workflow, inheriting the context and trigger data.
  5. Sub-workflow: process the payment — for POST payments, the POS — Process a payment sub-workflow takes over.
  6. Sub-workflow: handle the refund — for POST refunds, the POS — Handle a refund sub-workflow is executed.
  7. Reply 204 (not handled) — any other method or resource receives an HTTP response 204 No Content through the default branch of the switch.

What you need​

Construction​

Copy the workflow definition and paste it into the editor (the Trigger node is recreated automatically, it is not in the snippet):

[
{
"id": "code-109",
"name": "Identify the resource",
"config": {
"type": "CODE",
"code": "const method = context.incomingRequest.method;\nconst resource = context.incomingRequest.params.path;\ncontext.variables.route = `${method} ${resource}`;\nreturn context.variables.route;"
},
"parents": [
"trigger"
],
"position": {
"x": 0,
"y": 200
},
"next": "switch-109"
},
{
"id": "switch-109",
"name": "Request resource",
"config": {
"type": "SWITCH",
"variable": "{{ context.variables.route }}",
"cases": [
{
"value": "POST orders",
"next": "wf-order-109"
},
{
"value": "POST payments",
"next": "wf-payment-109"
},
{
"value": "POST refunds",
"next": "wf-refund-109"
}
],
"noMatchBehaviour": "reply-109"
},
"parents": [
"code-109"
],
"position": {
"x": 0,
"y": 400
}
},
{
"id": "wf-order-109",
"name": "Sub-workflow: register the order",
"config": {
"type": "CALL_WORKFLOW",
"workflow": "uuid-v4-caisse-commande",
"inherits": {
"context": true,
"data": true
}
},
"parents": [
"switch-109"
],
"position": {
"x": 800,
"y": 600
}
},
{
"id": "wf-payment-109",
"name": "Sub-workflow: process the payment",
"config": {
"type": "CALL_WORKFLOW",
"workflow": "uuid-v4-caisse-paiement",
"inherits": {
"context": true,
"data": true
}
},
"parents": [
"switch-109"
],
"position": {
"x": 800,
"y": 800
}
},
{
"id": "wf-refund-109",
"name": "Sub-workflow: handle the refund",
"config": {
"type": "CALL_WORKFLOW",
"workflow": "uuid-v4-caisse-remboursement",
"inherits": {
"context": true,
"data": true
}
},
"parents": [
"switch-109"
],
"position": {
"x": 800,
"y": 1000
}
},
{
"id": "reply-109",
"name": "Reply 204 (not handled)",
"config": {
"type": "HTTP_RESPONSE",
"statusCode": "204"
},
"parents": [
"switch-109"
],
"position": {
"x": 800,
"y": 1200
}
}
]

Check that it works​

  • Route convention: the switch compares the method space path string produced by the Code node — the case and spelling of the values (POST orders, …) must match exactly the events sent by the POS software.
  • Deploy the workflow (Deploy a workflow), then trigger the real scenario: every execution generates a trace you can view (View traces).

Variations​

  • Sub-workflow version: the Call a workflow node targets a specific version; after each change of a sub-workflow, update the selected version then re-deploy the calling workflow (see version management).
  • Unknown requests: the default branch replies 204 without processing; log unknown routes to spot API changes on the POS side.
  • Webhook response: each sub-workflow returns its result to the calling workflow; add an HTTP Response node at the end of the branch if the POS software expects an acknowledgement.

Going further


See also: Examples and integrations