Template functions
Some values change on every send: a request id, a timestamp, a random name. Template functions produce them inline, inside {{ }}, without writing a script.
POST {{baseUrl}}/events
X-Request-Id: {{ uuid() }}
X-Sent-At: {{ isoDate() }}
Authorization: Basic {{ base64Encode("api:secret") }}
::: body json
{
"id": "{{ uuid() }}",
"timestamp": {{ now() }},
"score": {{ randomInt(1, 100) }},
"nickname": "user-{{ randomString(6) }}"
}Functions
| Function | Arguments | Returns | Example result |
|---|---|---|---|
uuid() | none | A random UUID, version 4 | 3f2b8c1e-7a4d-4e8b-9f61-2c5d0a9b7e14 |
now() | none | Milliseconds since the Unix epoch | 1791302400000 |
isoDate() | none | The current UTC time, RFC 3339 | 2026-10-06T09:30:00Z |
randomInt(min, max) | two integers | A random integer between min and max, both included. If min is greater than max, they are swapped | 42 |
randomString(len) | one integer | A random string of letters and digits of that length, up to 1,048,576 characters. A longer or negative length fails | aZ3kQ9 |
base64Encode(str) | one string | Standard Base64 encoding | YXBpOnNlY3JldA== |
base64Decode(str) | one string | The decoded text. Fails if the input is not valid Base64 or does not decode to UTF-8 text | api:secret |
oauthToken(profile), oauthToken(profile, "id_token") | a profile name, and optionally "access_token" (default) or "id_token" | The token of that OAuth 2.0 profile for the active environment, obtained or renewed before the pre-request script, as the OAuth 2.0 auth type does. For a token in another header or in the body | eyJhbGciOi… |
urlEncode(str) | one string | Percent encoding. Letters, digits and - . _ ~ are kept as is | a%20b%26c |
Each call is evaluated on its own, so {{ uuid() }} written twice gives two different UUIDs. To reuse one value in several places, generate it once in a pre-request script with vars.set("id", util.uuid()) and write {{id}} wherever you need it.
Arguments
An argument is one of:
- A string in double quotes:
"user:pass". Inside it,\"is a quote and\\is a backslash. No other escapes exist. - An integer:
1,-5. - A variable name, without braces or quotes:
base64Encode(credentials)uses the value of the variablecredentials, looked up in the same layers as{{credentials}}.
GET {{baseUrl}}/search?q={{ urlEncode(searchTerm) }}
Authorization: Basic {{ base64Encode(basicCredentials) }}Here basicCredentials holds user:password in the environment, and searchTerm may contain spaces or symbols.
Calls cannot be nested and there are no operators: {{ base64Encode(urlEncode("x")) }} and {{ randomInt(1, 10) + 1 }} are not valid. Use a pre-request script for anything more involved.
Errors
An unknown function, the wrong number of arguments, an argument of the wrong type (a string where a number is expected) or an argument that names an unknown variable all behave like an unknown variable: the whole {{ … }} marker is sent exactly as written and the response shows a warning with the reason. A template function never stops a request.
The same functions in scripts
Every function except oauthToken() is also available in scripts as util.<name>(): util.uuid(), util.now(), util.base64Encode("text") and so on. They are the same implementation, so they behave identically and their error messages are word for word the same. In scripts, util.now() and util.randomInt() return numbers, the rest return strings. See the Script API.