API Academy
🌐 English
  • 🌐 English
  • 🌐 繁體中文
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. Testing APIs
  • Introduction
  • Table of Contents
  • API Academy
    • Get Started
      • What is an API?
      • How Does an API Work?
      • How to Call an API?
      • How to Read an API Documentation?
      • Chapter Summary
      • Get realtime weather
    • API Fundamentals
      • API Funtamentals: Overview
      • Method & Path
      • Parameters
      • Request Body
      • Responses
      • API Specification & OAS
      • Chapter Summary
    • Working with APIs
      • Working with APIs: Overview
      • Making Requests from Spec
      • Environments and Variables
      • Chaining Multiple Endpoints
      • Handling Authentication
      • Handling API Signatures
      • Introduction to Scripts
      • Chapter Summary
    • Mocking APIs
      • Mocking APIs: Overview
      • Smart Mock
      • Mock Expectations
      • Cloud Mock
      • Mock Scripts
      • Chapter Summary
    • Designing APIs
      • Designing APIs: Overview
      • Introduction to API Design
      • Creating Your First API Project
      • Analyzing Requirements and Planning Your API
      • Designing Data Models
      • Designing Endpoints
      • Using Components and Reusability
      • Setting Up Authentication
      • API Design Guidelines
      • Chapter Summary
    • Developing APIs
      • Developing APIs: Overview
      • Setup: Install Your AI Coding Assistant
      • Quick Start: From Spec to Running API in 30 Minutes
      • Understanding the Generated Code
      • Testing Your API with Apidog
      • Deployment: Put Your API Online
      • Chapter Summary
    • Testing APIs
      • Testing APIs: Overview
      • Getting Started: Your First Test Scenario
      • Integration Testing and Data Passing
      • Dynamic Values
      • Assertions and Validations
      • Flow Control: If, For, ForEach
      • Data-Driven Testing
      • Performance Testing
      • Test Reports and Analysis
      • CI/CD Integration
      • Scheduled Tasks and Automation
      • Advanced Testing Strategies
      • Chapter Summary
    • API Documentations
      • API Documentations: Overview
      • Publishing Your First API Doc
      • Customizing Documentation Appearance
      • Interactive Features for Consumers
      • Advanced Publishing Settings
      • Managing API Versions
      • Chapter Summary
    • Advanced API Technologies
      • API Technologies: Overview
      • GraphQL
      • gRPC
      • WebSocket
      • Socket.IO
      • Server-Sent Events (SSE)
      • SOAP
      • Chapter Summary
    • API Lifecycle
      • API Lifecycle: Overview
      • Stages of the API Lifecycle
      • API Governance
      • API Security Best Practices
      • Monitoring and Analytics
      • API Versioning Strategies
      • The Future of APIs
      • Chapter Summary
    • API Security
      • API Security: Overview
      • API Security Fundamentals
      • Authentication vs Authorization
      • Understanding OAuth 2.0 and OpenID Connect
      • JSON Web Tokens (JWT)
      • OWASP API Security Top 10
      • Encryption and HTTPS
      • Chapter Summary
    • API Tools
      • API Tools: Overview
      • The Evolution of API Tools
      • API Clients
      • Command Line Tools (cURL, HTTPie)
      • API Design and Documentation Tools
      • API Mocking Tools
      • API Testing Tools
      • All-in-One API Platforms
      • Chapter Summary
    • API Gateway
      • API Gateway: Overview
      • What is an API Gateway?
      • Key Features of API Gateways
      • API Gateway vs Load Balancer vs Service Mesh
      • Popular API Gateway Solutions
      • The BFF (Backend for Frontend) Pattern
      • Chapter Summary
  • Modern Pet Store
    • Pet
      • Get Pet
      • Update Pet
      • Delete Pet
      • Create Pet
      • List Pets
      • Upload Pet Image
    • User
      • Update User
      • Get User
      • Delete User
      • Login
      • Logout
      • Create User
    • Store
      • List Inventory
      • Create Order
      • Get Order
      • Delete Order
      • Callback Example
      • Pay for an Order
    • Payments
      • Pay Order
    • Chat
      • Create Chat Completion
    • Webhooks
      • Pet Adopted Event
      • New Pet Available Event
  • Schemas
    • Pet
    • Category
    • User
    • ApiResponse
    • OrderPayment
    • Tag
    • Order
    • Links-Order
    • PetCollection
    • Bank Card
    • Bank Account
    • Links
    • Error
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. Testing APIs

Dynamic Values

In the previous chapter's "User Lifecycle" example, we briefly mentioned using {{$randomUserName}} to verify user registration. This simple trick is actually part of a powerful feature called Dynamic Values.
When you pass data between steps, you're using real data. But often, you need fake but realistic data to make your tests robust and repeatable.
To solve this, we use Dynamic Values.

What are Dynamic Values?#

Dynamic values are special variables built into Apidog (similar to "Faker" libraries) that generate random data every time the request is sent.
They follow the syntax {{$variableName}}.

Why use them?#

1.
Avoid Collisions: Never get "Duplicate Key" errors.
2.
Realism: Test with different names, emails, and numbers every time.
3.
Convenience: No need to manually type "test user 1", "test user 2".

Common Dynamic Variables#

Here are the most useful ones for everyday testing:

Identifiers#

{{$guid}}: A unique UUID (e.g., d4f5-a1b2-...). Perfect for Request IDs or Trace IDs.
{{$timestamp}}: Current Unix timestamp (e.g., 1678886472).

Personal Data#

{{$randomUserName}}: A random username (e.g., brave_lion).
{{$randomEmail}}: A random email (e.g., example@xyz.com).
{{$randomPhoneNumber}}: A random phone number.

Numbers & Strings#

{{$randomInt}}: A random integer between 0 and 1000.
{{$randomString}}: A random string of text.
Tip: Apidog provides hundreds of these. Just type {{$ in any value field, and the autocomplete list will appear. Or click the Magic Wand icon to browse the full list.
Dynamic Value Selector

Real Case: Random User Registration#

Let's fix our "User Registration" test so it never fails with a duplicate email error.
Old Body (Static):
{
  "username": "testuser",
  "email": "test@example.com",
  "password": "Password123"
}
New Body (Dynamic):
{
  "username": "{{$randomUserName}}",
  "email": "{{$randomUserName}}@example.com",
  "password": "Password123"
}
Now, every time you run this test, Apidog generates a fresh user:
Run 1: "username": "blue_sky"
Run 2: "username": "fast_tiger"

Using Dynamic Values in Parameters#

You can also use them in query parameters.
GET /items?cacheBuster={{$timestamp}}
This ensures the server never returns a cached response because the URL is always unique.

Key Takeaways#

Use Dynamic Values to prevent data collision and "Duplicate Key" errors.
Master common variables like {{$timestamp}}, {{$guid}}, and {{$randomUserName}}.
Apply dynamic data to make your tests robust and repeatable without manual cleanup.

What's Next#

Now that we have data flowing between requests (Integration) and unique data for every run (Dynamic Values), we need to ensure the API is actually returning the correct results.
In the next chapter, we'll dive into Assertions and Validations.
Continue with β†’ Assertions and Validations
Modified atΒ 2025-12-25 09:53:04
Previous
Integration Testing and Data Passing
Next
Assertions and Validations
Built with