Variables & Dynamic Functions

Use variables and dynamic functions to make your requests dynamic, generate test data, and create powerful API workflows.

Overview

Echolon provides a powerful variable system that goes beyond simple environment variables. You can use the {{expression}} syntax to:

  • Reference environment variables
  • Generate random data (names, emails, numbers, etc.)
  • Create unique identifiers (UUIDs)
  • Generate timestamps in various formats
  • Encode/decode values (Base64, URL encoding)
  • Create hashes (MD5, SHA-256, etc.)
  • Access context information (workspace, collection IDs)

Variables and functions can be used in URLs, query parameters, headers, request bodies, and scripts.

Variable Types

Environment variables are defined at different scopes with the following priority (highest to lowest):

  • Collection Environment Variables: Scoped to a collection's environment (e.g., "Production", "Staging")
  • Collection Variables: Scoped to a specific collection
  • Global Environment Variables: Available everywhere in the active global environment

If a variable name exists in multiple scopes, the higher-priority scope takes precedence. This allows you to override global variables with collection-specific values.

Syntax

Reference variables using double curly braces:

{{baseUrl}}/users/{{userId}}

For functions with parameters, use named arguments:

{{random.range(min=1, max=100)}}
{{timestamp.format(format="YYYY-MM-DD")}}

Functions without parameters can be called directly:

{{uuid.v4}}
{{timestamp.iso8601}}

Dynamic Functions

Dynamic functions generate values at request time. They are organized into categories and can be discovered by typing {{ in any input field.

Random Functions

Generate random data for testing and mock scenarios.

FunctionDescriptionExample Output
random.range(min, max, decimals?) Random number between min and max 42
random.integer(min?, max?) Random integer 847
random.float(min?, max?, decimals?) Random floating-point number 0.73
random.boolean Random true/false true
random.firstName Random first name Emma
random.lastName Random last name Johnson
random.fullName Random full name James Wilson
random.email(domain?) Random email address john.doe42@example.com
random.phone(format?) Random phone number (555) 123-4567
random.username Random username cool_ninja42
random.password(length?) Random password xK9#mP2@nL5$
random.alphanumeric(length?) Random alphanumeric string a7Bk9mNp
random.word Random word ocean
random.sentence(words?) Random sentence Quick brown fox jumps.
random.paragraph(sentences?) Random paragraph Lorem ipsum dolor sit amet...
random.company Random company name Tech Solutions
random.address Random street address 123 Main Street
random.city Random city name Seattle
random.country Random country name Canada
random.hexColor Random hex color #3a7bd5
random.ipv4 Random IPv4 address 192.168.1.42
random.ipv6 Random IPv6 address 2001:0db8:85a3:...
random.url Random URL https://example.com/api
random.date(start?, end?) Random date 2024-06-15
random.creditCard Random test card number 4532 1234 5678 9012

UUID Functions

Generate universally unique identifiers.

FunctionDescriptionExample Output
uuid.v1 Time-based UUID (v1) 6ba7b810-9dad-11d1-80b4-...
uuid.v4 Random UUID (v4) 550e8400-e29b-41d4-a716-...

Hash Functions

Generate cryptographic hashes. If no input is provided, a random string is hashed.

FunctionDescriptionExample Output
hash.md5(input?) MD5 hash d41d8cd98f00b204e980...
hash.sha1(input?) SHA-1 hash da39a3ee5e6b4b0d3255...
hash.sha256(input?) SHA-256 hash e3b0c44298fc1c149afb...
hash.sha512(input?) SHA-512 hash cf83e1357eefb8bdf154...

Timestamp Functions

Generate timestamps in various formats.

FunctionDescriptionExample Output
timestamp.now Current timestamp (ms) 1704067200000
timestamp.unix Unix timestamp (seconds) 1704067200
timestamp.unixMillis Unix timestamp (milliseconds) 1704067200000
timestamp.iso8601 ISO 8601 format 2024-01-01T00:00:00.000Z
timestamp.date Date only (YYYY-MM-DD) 2024-01-01
timestamp.time Time only (HH:mm:ss) 14:30:45
timestamp.format(format?) Custom format 2024-01-01 14:30:45

Format tokens for timestamp.format:

  • YYYY - 4-digit year
  • MM - 2-digit month (01-12)
  • DD - 2-digit day (01-31)
  • HH - 2-digit hour (00-23)
  • mm - 2-digit minutes (00-59)
  • ss - 2-digit seconds (00-59)
  • SSS - 3-digit milliseconds

Encoding Functions

Encode and decode strings.

FunctionDescriptionExample
base64.encode(value) Base64 encode helloaGVsbG8=
base64.decode(value) Base64 decode aGVsbG8=hello
url.encode(value) URL encode hello worldhello%20world
url.decode(value) URL decode hello%20worldhello world

JSON Functions

Manipulate JSON data.

FunctionDescription
json.minify(json) Remove whitespace from JSON
json.escape(value) Escape string for JSON
json.stringify(value) Convert to JSON string

Context Functions

Access information about the current context.

FunctionDescription
ctx.workspace Current workspace ID
ctx.environment Current environment ID
ctx.collection Current collection ID
ctx.request Current request ID

Function Configuration

When you click on a function in the autocomplete dropdown, a configuration modal opens where you can:

  • Set parameter values using input fields
  • See a live preview of the generated value
  • Regenerate the preview to see different random values
  • Insert the configured function into your request

Double-clicking on an existing function in a field will reopen the configuration modal, allowing you to modify its parameters.

Use Cases

1. Generate Unique User Data for Testing

POST /api/users
Content-Type: application/json

{
  "id": "{{uuid.v4}}",
  "firstName": "{{random.firstName}}",
  "lastName": "{{random.lastName}}",
  "email": "{{random.email}}",
  "createdAt": "{{timestamp.iso8601}}"
}

2. Create Authenticated Requests with Timestamps

GET /api/data
Authorization: Bearer {{apiToken}}
X-Request-ID: {{uuid.v4}}
X-Timestamp: {{timestamp.unix}}

3. Generate Random Test Data

POST /api/orders
Content-Type: application/json

{
  "orderId": "ORD-{{random.alphanumeric(length=8)}}",
  "amount": {{random.range(min=10, max=500, decimals=2)}},
  "items": {{random.integer(min=1, max=10)}},
  "shippingAddress": "{{random.address}}, {{random.city}}"
}

4. URL-Encoded Query Parameters

GET /api/search?q={{url.encode(value="hello world")}}&timestamp={{timestamp.unix}}

5. Generate API Signatures

POST /api/webhook
X-Signature: {{hash.sha256(input="{{secretKey}}{{timestamp.unix}}")}}
X-Timestamp: {{timestamp.unix}}

6. Base64-Encoded Credentials

Authorization: Basic {{base64.encode(value="{{username}}:{{password}}")}}