Skip to main content

Dynamic Variables


What are dynamic variables

Dynamic variables in Koxy AI are variables that can change their value over time or with every request to your API. They can be used to make your APIs more flexible and adaptable. They can be used to get a variables from your saved environment variables, previous node's responses, or request parameters.


Dynamic variables types

  • Environment variables: variables that are stored in the cloudspace's environment. Can be accessed using the koxy.env.{variable} syntax.

  • Responses variables: used to access the response of a previously executed node. Can be accessed using the koxy.res.{node_name} syntax.

  • Parameters: variables that are passed to the API with every run (request). Can be accessed using the koxy.get.{parameter_name} syntax.

  • Variables: variables that are stored using the create variable node. Can be accessed using the koxy.var.{var_key} syntax.

  • Headers: used to get a specific header from the request headers. Can be accessed using the koxy.header.{header_name} syntax.


How to use dynamic variables

You can use dynamic variables in any node's property that support dynamic variables. in every node documentation you will find a section called Dynamic variables support explains what properties support using variables.

Dynamic variables are treated based on the data type of their values and the type of node you're using, for example in conditional nodes, if the variable's value is a string you should use it like this "koxy.env.{my_variable}", but if it's a number or a boolean value you can use it like this koxy.env.{my_variable}.

For example, the conditions node supports using variables in its operands, so we can set an operand value as koxy.env.{my_variable} or any other dynamic variable.

If there is any exceptions on how to use dynamic variables in a node you'll find about it in its documentation.


Undefined variables

If the variable is not found the system will return "undefined" as the variable's value.


Environment variables

Use environment variables to store API keys and other configuration values and secrets. You can access them in your nodes using the following syntax: koxy.var.{variable_key}

Add a variable

You can add a new environment variable to your API by navigating to your cloudspace, click on the environment icon (the second icon in the bottom-right corner) and click on New variables, give your new variables a key (name) and a value and click on Add variable.

Benefits

  • Secure way to store sensitive information.

  • easy to access from any process or node running in your API.

How to edit a variables's value

To edit a variable's value you would add a new variable with the same key of the variable you want to edit, the new value you enter as the new variable will replace the existing one.


Parameters

You can send parameters with your api request's body and they can be accessed using the following syntax: koxy.get.{PARAMETER_NAME}.

Using Koxy JS

import { koxyRun } from 'koxy-js';

const configs = {
cloudspace: CLOUDSPACE_TOKEN
parameters: {
param1: "value1",
param2: "value2"
},
};

const run = await koxyRun(configs);

With HTTP requests

--data '{"parameters": {"param1": "value1"}}'

Responses

See Nodes responses for more information.

Variables

See Create variable node for more information.

Headers

You can send custom headers to your API and get them using the koxy.header.{header_key} syntax.

example: koxy.header.{apiKey} will get the value of the apiKey header sent with your request.