Generating dynamic values
Fill requests with fresh IDs, timestamps and sample data each time they're sent.
Overview
Dynamic variables generate a new value each time a request is sent. Use them for values that must be unique, such as an idempotency key, for the current time, or for realistic test data such as names and email addresses.
Relay supports the same 118 dynamic variables as Postman, with the same names, so requests you import from Postman keep working. Each one starts with $:
{
"id": "{{$guid}}",
"email": "{{$randomEmail}}",
"name": "{{$randomFullName}}",
"createdAt": "{{$isoTimestamp}}"
}Use a dynamic variable
Write a dynamic variable like any other, wherever a request accepts variables: {{$timestamp}}, {{$randomInt}}, {{$randomUUID}}. Names are case-sensitive, so {{$randomEmail}} works and {{$RandomEmail}} doesn't.
Every occurrence gets its own value. A request that uses {{$guid}} twice sends two different IDs, and each send generates new ones. The same applies to a variable whose value contains a dynamic variable: if you define orderId as {{$guid}}, each {{orderId}} in a request gets a new ID.
To use one generated value in several places, generate it in a pre-request script and store it for the send:
relay.variables.set("orderId", relay.variables.replaceIn("{{$guid}}"));Every {{orderId}} in the request then has the same value. For more information, see Reading and writing variables in scripts.
Preview dynamic values
Dynamic variables get their values only when a request is sent. Everywhere else, they stay as written: the request preview and generated code show {{$guid}} rather than a value.
To see what a dynamic variable produces, hold the pointer over it in a field. The tooltip shows Dynamic Variable, an example value and a description.
Override a dynamic variable
A variable you define always wins over a dynamic variable with the same name. If a workspace, environment, collection or folder defines $timestamp, requests use that value instead of the current time.
A $ name that's neither defined nor one of the dynamic variables is treated like any other undefined variable, and its token is sent as written.
Browse the categories
The dynamic variables are grouped the same way as in Postman:
| Category | Count | Examples |
|---|---|---|
| Common | 4 | $guid, $timestamp, $isoTimestamp, $randomUUID |
| Text, numbers, and colors | 6 | $randomAlphaNumeric, $randomBoolean, $randomInt, $randomHexColor |
| Internet and IP addresses | 8 | $randomIP, $randomIPV6, $randomPassword, $randomUserAgent |
| Names | 5 | $randomFirstName, $randomLastName, $randomFullName |
| Profession | 4 | $randomJobTitle, $randomJobArea |
| Phone, address, and location | 9 | $randomPhoneNumber, $randomCity, $randomCountryCode, $randomLatitude |
| Images | 15 | $randomAvatarImage, $randomImageUrl, $randomImageDataUri |
| Finance | 10 | $randomBankAccountIban, $randomCurrencyCode, $randomCreditCardMask |
| Business | 6 | $randomCompanyName, $randomBs |
| Catchphrases | 4 | $randomCatchPhrase |
| Databases | 4 | $randomDatabaseColumn, $randomDatabaseType |
| Dates | 5 | $randomDateFuture, $randomDatePast, $randomWeekday |
| Domains, emails, and usernames | 7 | $randomEmail, $randomExampleEmail, $randomUserName, $randomUrl |
| Files and directories | 9 | $randomFileName, $randomMimeType, $randomFilePath |
| Stores | 6 | $randomPrice, $randomProductName |
| Grammar | 7 | $randomNoun, $randomVerb, $randomWords |
| Lorem ipsum | 9 | $randomLoremWord, $randomLoremSentence, $randomLoremParagraph |
For every variable with a description and an example, see Dynamic variables.
See Also
- Dynamic variables: Dynamic variables that generate a new value each time a request is sent.
- Using variables: Insert values into requests with
{{name}}tokens and see where each value comes from. - Reading and writing variables in scripts: Read variables and set new values from pre-request and post-response scripts.