DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Shallow and Deep Copies in JavaScript: What’s the Difference?
  • Ultimate Guide to FaceIO
  • What Is Ant, Really?
  • When One Giant Payload Must Serve Many Small Consumers: Designing a Scalable Fanout Service

Trending

  • When Your Documentation Manages Itself: mdship and AI-Assisted Markdown
  • OpenAPI, ORM, SVG, and Lottie
  • A Spring Boot App With Half the Startup Time
  • GenAI Isn't Solving the Problem Most Development Teams Actually Have
  1. DZone
  2. Coding
  3. Languages
  4. Accessing Payload, Variables and Environment Properties in Kumologica

Accessing Payload, Variables and Environment Properties in Kumologica

This article will demonstrate how to access or manipulate message payload, variables, and environment variables inside Kumologica flow.

By 
Rohini Arun kumar user avatar
Rohini Arun kumar
·
Oct. 22, 20 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
8.3K Views

Join the DZone community and get the full member experience.

Join For Free

A Kumologica API or service integration can be represented as a connected network of nodes, each node is responsible to take a message (request) and produce zero or many outputs, which in turn becomes the input to the next node. A Kumologica flow uses only 3 elements for the propagation and manipulation of data when moving from one node to the other. 

1. Message — msg

2. Variables — vars

3. Environment — env

flow execution

Message

Message (msg) object is a piece of information that node use to communicate with each other. Nodes work on the object their predefined logic and modify the object. The basic structure of the message object is as follows.

_msgrid

  • _msgid: Unique execution identifier created for each execution. 
  • error: This property will hold the error being caught by the Error Node. 
  • header: This property is an object hold metadata added by a node. Information contained in this object should not be modified by other nodes.
  • payload: This property is an object hold information added by the node. Unlike the header property, this property is meant to be mutable, and it has a special meaning for some nodes. 

How to Access Message Object?

Message object can be accessed in all the nodes with the expression msg. You may access the payload inside the message using the expression msg.payload. Based on the object type of within the payload the content can be further traversed down. Eg: Let's assume that a payload is a JSON object with the following structure.

JSON
 




x





1
{
2
  "details" : {
3
    "name" : "kumo",
4
    "location" : "Kerala"
5
  },
6
  "Country" : "India" 
7
}



In the above JSON payload, the location field can be accessed in any nodes using the following expression.

msg.payload.details.location

Now to set a value to the location filed in the same JSON payload can be done using different ways like using Set-Property node, Datamapper node, or a Function node. Inside the function node, you can set the value to the above-shown JSON payload as given below.

msg.payload.details.location = 'Delhi' 

Or if you want to introduce a new field in the existing payload you can do as follows.

msg.payload.direction = "South"

This will result in the below-given payload output.

JSON
 




xxxxxxxxxx
1


 
1
{
2
  "details" : {
3
    "name" : "kumo",
4
    "location" : "Kerala"
5
  },
6
  "Country" : "India" ,
7
  "Direction" : "South"
8
}



Similarly, you can introduce a new field directly on the msg object structure as well.

msg.mydata = "testdata"

Variables

Variables are temporary storage which can be used when you want to preserve certain content like payload which can be further used at any point in the flow. Variables like message object can be accessed using the expression vars. You can set a variable either using a Set-Property node or a Function node.

How to Access Variable Object?

Inside the Set-Property node, you need to select $vars from the drop-down to create and initialize a variable.

rules

Then provide the variable name. On the to section provide the value you want to set on the variable. For example, in the below Set-Property, I am setting payload inside the variable with the name "mytemp".

rules

You can access the variable to retrieve the content similar to the message object. Eg. Assume that the JSON payload mentioned in the earlier example in the message section is stored in the variable mytemp using the Set-Property node as shown above. We can access the location field in the JSON structure using the below-given expression.

vars.details.location

Environment

Environment variable unlike the regular variable is set from outside the context of Kumologica flow. These are variables injected as part of the environment properties of your lambda application.

How to Access Environment Object?

Environment variables can be accessed using the expression env. The property can be accessed in any node using the following expression. Eg. I have a database hostname that is set as part of the environment and I need to access it inside the flow. 

env.db.hostname

Summary

Know the above 3 elements of Kumologica flow you can manipulate data whichever way you like to build your cool application. All the expressions covered in this article are fundamentally JSONata expressions which means that you can apply the principles of JSONata for the manipulation of your data.

Payload (computing) Property (programming) Object (computer science)

Opinions expressed by DZone contributors are their own.

Related

  • Shallow and Deep Copies in JavaScript: What’s the Difference?
  • Ultimate Guide to FaceIO
  • What Is Ant, Really?
  • When One Giant Payload Must Serve Many Small Consumers: Designing a Scalable Fanout Service

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook