First workflow — fictitious customer and loyalty-based response
The need
You are new to Ecosystem and want to get hands-on with the editor without any business stakes: this workflow generates a fictitious customer, evaluates their loyalty score, then responds differently depending on the result. It illustrates the first reflexes of the editor — manipulating context, writing a condition and producing an HTTP response — on a complete, ready-to-replay workflow.
What the workflow does
- Customer request — the API Trigger node receives a request and starts the execution. The request data arrives in
data. - Generate a fictitious customer — the Code node builds a customer object (
firstName,lastName,birthDate,address,loyaltyScore) incontext.customer, usinglibs.uuid(),libs.dayjs()andlibs.lodash.random(). - Loyal customer? — the Condition node evaluates
context.customer.loyaltyScore >= 50, written in plain JavaScript withreturn(not Handlebars syntax). - VIP customer response — if the score reaches 50, an HTTP Response node returns
SUCCESS_VIP. - Standard success response — otherwise, a second HTTP Response node returns
SUCCESS_STANDARD.
In this workflow, only one of the two responses can run thanks to the condition; without an exclusive branch, the workflow would try to emit two responses.
What you need
- An account with creation rights (Builder, Advanced Builder or Company Owner roles) — see First steps
The Trigger node is recreated automatically by importing the snippet: you don't have to create anything by hand.
Construction
- Copy the workflow definition below.
- Open a workflow editor and paste the definition: the workflow is rebuilt with the Code node, the condition and the two HTTP responses.
- Name the Trigger node and check that each node is configured as described in What the workflow does.
[
{
"id": "code-101",
"name": "Generate a fictitious customer",
"config": {
"type": "CODE",
"code": "const firstNames = ['Marie', 'Jean', 'Sophie', 'Paul', 'Léa', 'Hugo'];\nconst lastNames = ['Martin', 'Bernard', 'Dubois', 'Moreau', 'Laurent', 'Girard'];\nconst streetNames = ['Peace Street', 'Victor-Hugo Avenue', 'Voltaire Boulevard', 'National Street'];\nconst cities = ['Paris', 'Lyon', 'Marseille', 'Nantes'];\n\ncontext.customer = {\n id: libs.uuid(),\n firstName: firstNames[Math.floor(Math.random() * firstNames.length)],\n lastName: lastNames[Math.floor(Math.random() * lastNames.length)],\n birthDate: libs.dayjs().subtract(Math.floor(18 + Math.random() * 50), 'years').format('YYYY-MM-DD'),\n address: {\n street: `${Math.floor(1 + Math.random() * 120)} ${streetNames[Math.floor(Math.random() * streetNames.length)]}`,\n city: cities[Math.floor(Math.random() * cities.length)],\n },\n loyaltyScore: libs.lodash.random(0, 100),\n};"
},
"parents": [
"trigger"
],
"position": {
"x": 400,
"y": 200
},
"next": "cond-101"
},
{
"id": "cond-101",
"name": "Loyal customer?",
"config": {
"type": "CONDITION",
"conditionCode": "return context.customer.loyaltyScore >= 50;",
"conditions": [
{
"value": true,
"next": "vip-101"
},
{
"value": false,
"next": "std-101"
}
]
},
"parents": [
"code-101"
],
"position": {
"x": 400,
"y": 400
}
},
{
"id": "vip-101",
"name": "VIP customer response",
"config": {
"type": "HTTP_RESPONSE",
"statusCode": "200",
"headers": {
"Content-Type": "application/json"
},
"responseTemplate": "{\n \"status\": \"SUCCESS_VIP\",\n \"message\": \"Welcome to the VIP club, {{ context.customer.firstName }}!\",\n \"loyaltyScore\": {{ context.customer.loyaltyScore }}\n}"
},
"parents": [
"cond-101"
],
"position": {
"x": 0,
"y": 600
}
},
{
"id": "std-101",
"name": "Standard success response",
"config": {
"type": "HTTP_RESPONSE",
"statusCode": "200",
"headers": {
"Content-Type": "application/json"
},
"responseTemplate": "{\n \"status\": \"SUCCESS_STANDARD\",\n \"message\": \"Thank you for your purchases, keep earning points!\",\n \"loyaltyScore\": {{ context.customer.loyaltyScore }}\n}"
},
"parents": [
"cond-101"
],
"position": {
"x": 800,
"y": 600
}
}
]
Check that it works
- Select the Code node (Generate a fictitious customer) then click Test the node.
- Run the execution with test data (e.g.
{ "orderId": "CMD-4821" }). - In the trace, the Code node displays the generated customer in
context.customer, and the execution ends with one of the two HTTP responses —SUCCESS_VIPifloyaltyScorereaches 50,SUCCESS_STANDARDotherwise. Run it several times: since the score is random, both branches execute over the course of the tests.
The testing procedure is described in Test a workflow.
Variations
- Change the loyalty threshold in the Condition node to explore other branches.
- Customize the response bodies with customer data (
context.customer) — HTTP Response node. - Chain a follow-up process based on the result instead of responding — Condition node.
See also: First steps · Examples and integrations