Variables and Environments

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:

CategoryCountExamples
Common4$guid, $timestamp, $isoTimestamp, $randomUUID
Text, numbers, and colors6$randomAlphaNumeric, $randomBoolean, $randomInt, $randomHexColor
Internet and IP addresses8$randomIP, $randomIPV6, $randomPassword, $randomUserAgent
Names5$randomFirstName, $randomLastName, $randomFullName
Profession4$randomJobTitle, $randomJobArea
Phone, address, and location9$randomPhoneNumber, $randomCity, $randomCountryCode, $randomLatitude
Images15$randomAvatarImage, $randomImageUrl, $randomImageDataUri
Finance10$randomBankAccountIban, $randomCurrencyCode, $randomCreditCardMask
Business6$randomCompanyName, $randomBs
Catchphrases4$randomCatchPhrase
Databases4$randomDatabaseColumn, $randomDatabaseType
Dates5$randomDateFuture, $randomDatePast, $randomWeekday
Domains, emails, and usernames7$randomEmail, $randomExampleEmail, $randomUserName, $randomUrl
Files and directories9$randomFileName, $randomMimeType, $randomFilePath
Stores6$randomPrice, $randomProductName
Grammar7$randomNoun, $randomVerb, $randomWords
Lorem ipsum9$randomLoremWord, $randomLoremSentence, $randomLoremParagraph

For every variable with a description and an example, see Dynamic variables.

See Also