Variables Class Documentation

Variables

A comprehensive C# wrapper class for managing variables through HTTP API calls

Configure Configure 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 GetVariableAsync

public async Task<JsonElement> GetVariableAsync(string name)

Retrieves a specific variable by its name from the API.

📝 Parameters

name (string) - The name of the variable to retrieve

â†Šī¸ Returns

Task<JsonElement?> - The retrieved variable data, or null if not found

💡 Example

var variable = await Variables.GetVariableAsync("myVariable");
if (variable.HasValue)
{
    Console.WriteLine($"Variable found: {variable.Value}");
}
else
{
    Console.WriteLine("Variable not found");
}

GET GetAllVariablesAsync

public async Task<JsonElement> GetAllVariablesAsync()

Retrieves all variables from the API.

â†Šī¸ Returns

Task<JsonElement> - All variables data as a JSON element

💡 Example

var allVariables = await Variables.GetAllVariablesAsync();
var variableArray = allVariables.EnumerateArray();

foreach (var variable in variableArray)
{
    foreach (var prop in variable.EnumerateObject())
    {
        Console.WriteLine($"{prop.Name}: {prop.Value}");
    }
}

POST CreateVariableAsync

public async Task<JsonElement> CreateVariableAsync(object data)

Creates a new variable with the specified data.

📝 Parameters

data (object) - The variable data to create. Can be any serializable object.

â†Šī¸ Returns

Task<JsonElement> - The created variable data returned from the API

💡 Example

var newVariable = new 
{
    name = "temperature",
    value = "25.5",
    type = "number"
};

var result = await Variables.CreateVariableAsync(newVariable);
Console.WriteLine($"Created variable: {result}");

PUT UpdateVariableAsync

public async Task<JsonElement> UpdateVariableAsync(string name, object newValue)

Updates an existing variable with a new value.

📝 Parameters

name (string) - The name of the variable to update
newValue (object) - The new value for the variable

â†Šī¸ Returns

Task<JsonElement> - The updated variable data returned from the API

💡 Example

// Update a variable with a new value
var result = await Variables.UpdateVariableAsync("temperature", "30.2");
Console.WriteLine($"Updated variable: {result}");

📤 Request Body Structure

The method automatically wraps the new value in a JSON object:

{
"value": <newValue>
}