Variables
A comprehensive JavaScript wrapper class for managing variables through HTTP API calls
ConfigureConfigure API url
public static void <JsonElement> configure(string apiUrl)
Specify a custom API url.
âŠī¸ Returns
void
đĄ Example
Variables.configure("https://prod-api.mycompany.com")
GET getVariable
async getVariable(name: string): Promise<any>
Retrieves a specific variable by its name from the API.
đ Parameters
name (string) - The name of the variable to retrieve
âŠī¸ Returns
Promise<any> - The retrieved variable data, or null if not found
đĄ Example
const variable = await Variables.getVariable("myVariable");
if (variable) {
console.log(`Variable found: ${JSON.stringify(variable)}`);
} else {
console.log("Variable not found");
}
GET getAllVariables
async getAllVariables(): Promise<any>
Retrieves all variables from the API.
âŠī¸ Returns
Promise<any> - All variables data
đĄ Example
const allVariables = await Variables.getAllVariables();
for (const variable of allVariables) {
for (const [key, value] of Object.entries(variable)) {
console.log(`${key}: ${value}`);
}
}
POST createVariable
async createVariable(data: Record<string, any>): Promise<any>
Creates a new variable with the specified data.
đ Parameters
data (Record<string, any>) - The variable data to create. Can be any object with string keys.
âŠī¸ Returns
Promise<any> - The created variable data returned from the API
đĄ Example
const newVariable = {
name: "temperature",
value: "25.5",
type: "number"
};
const result = await Variables.createVariable(newVariable);
console.log(`Created variable: ${JSON.stringify(result)}`);
PUT updateVariable
async updateVariable(name: string, new_value: string | number | boolean): Promise<any>
Updates an existing variable with a new value.
đ Parameters
name (string) - The name of the variable to update
new_value (string | number | boolean) - The new value for the variable
âŠī¸ Returns
Promise<any> - The updated variable data returned from the API
đĄ Example
// Update a variable with a new value
const result = await Variables.updateVariable("temperature", "30.2");
console.log(`Updated variable: ${JSON.stringify(result)}`);
đ¤ Request Body Structure
The method automatically wraps the new value in a JSON object:
{
"value": <new_value>
}