Variables in KurocoEdge
Overview
Within Rules' Actions, KurocoEdge primarily handles variables in 3 different ways:
This document will give a brief overview of each type of variable, and offer basic guidance and best practices for usage.
Each of the variable types can be created and managed within the 'Conditions / Variables' section of any Action within a Rule.
Static Variables
Static variables can be explicitly assigned within the 'Conditions / Variables' section of an Action, by creating a new 'Static variable' in the select/dropdown menu of an item.
This is the most basic form of variable that can be used in KurocoEdge.
Why Use Static Variables?
As in any programming language, it is useful to be able to define variables to store a value that can be easily called later (without having to repeat the value).
Static variables can be used in the fields of an Action's 'Execution' section, for a cleaner and more efficient way of entering in values.
For a tutorial on how to create and use Static Variables, refer to the following document:
Using Variables in KurocoEdge – Static Variables
Captured Variables
Unlike 'Static' or 'API' variables, which are explicitly defined in the 'Conditions / Variables' section of an Action, KurocoEdge also allows you to define special 'Captured' variables within a Rule's Action. This type of variable is created as a captured 'Field settings' value.
For example, in 'Conditions / Variables' you can choose a 'Header', 'Body prefix', or 'Match variable value' field, and capture its current value using the regular expression syntax (?P<name>…)
.
Why Use Captured Variables?
This is a convenient, and highly versatile way to create variables 'on-the-fly' in KurocoEdge. These captured variables can then be reused like other KurocoEdge variables within the Action's 'Execution' section, with the {$variable}
syntax.
A common use case is to capture a value and insert it as a parameter in a URL (ex. when making an API call to fetch data).
For a tutorial on how to create and use Captured Variables, refer to the following document: Using Variables in KurocoEdge – Captured Variables
API Variables
The most advanced form of variable in KurocoEdge is the API variable. This allows you to assign a value fetched from an API endpoint to a variable. API variables can be used within an Action's 'Execute' section, the same way a Static Variable can be. However, it can be more complicated to assign a value to an API variable, as the API data is often an object with nested values.
In order to access nested values, it is necessary to use dot notation.
For example, if an API variable (object) called address
contains a nested value of street
the correct syntax to use in the 'Execution' section is:
{$address.street}
Generally, when using an API variable, it is a best practice to either return a top-level string value (from a top-level key/value pair within an object), or use dot notation to return a nested string value.
Why Use API Variables?
Working with API response objects can be complicated and unwieldy. Assigning a value (or nested value) to a variable can make it easier to work with - for example, when you need to insert a value as a parameter in a URL or when fetching dynamic data from an API endpoint.
For a more advanced tutorial on how to create and use API Variables, refer to the following document:
Using Variables in KurocoEdge – API Variables
Support
If you have any other questions, please contact us or check out Our Discord Community.