Apidog Docs
🇺🇸 English
  • 🇺🇸 English
  • 🇯🇵 日本語
HomeLearning CenterSupport CenterAPI References
HomeLearning CenterSupport CenterAPI References
Discord Community
Slack Community
X / Twitter
🇺🇸 English
  • 🇺🇸 English
  • 🇯🇵 日本語
  1. Mock API data
  • Apidog Learning Center
  • Get started
    • Introduce Apidog
    • Basic concepts in Apidog
    • Navigating Apidog
    • Quick Start
      • Overview
      • Specify a new endpoint
      • Make a request to the endpoint
      • Add an assertion
      • Create a test scenario
      • Share your API documentation
      • Explore more
      • Send a request and save as an endpoint
    • Migration
      • Overview
      • Manual import
      • Scheduled import
      • Import options
      • Export data
      • Import from...
        • Import from Postman
        • Import OpenAPI (Swagger) spec
        • Import cURL
        • Import Markdowns
        • Import from Insomnia
        • Import from apiDoc
        • Import .har file
        • Import WSDL
  • Design APIs
    • Overview
    • Create a new API project
    • Endpoint basics
    • Components
    • Common fields
    • Global parameters
    • Endpoint change history
    • Batch endpoint management
    • Configure multiple request body examples
    • Schemas
      • Generate Schemas from JSON etc.
      • Build a schema
      • Overview
      • Create a new schema
    • Security schemes
      • Overview
      • Create a security scheme
      • Use the security scheme
      • Security scheme in online documentation
    • Advanced features
      • Custom endpoint fields
      • Import endpoints as test steps
      • Endpoint status
      • Appearance of parameter lists
      • Endpoint unique idenfication
  • Develop and Debug APIs
    • Overview
    • Generate requests
    • Send requests
    • Endpoint cases
    • Dynamic values
    • Validate responses
    • Design-first Mode & Request-first Mode
    • Generate code
    • Environments & variables
      • Overview
      • Using variables
      • Environments & services
    • Vault secrets
      • Overview
      • HashiCorp Vault
      • Azure Key Vault
      • AWS Secrets Manager
    • Pre/Post processors
      • Overview
      • Assertion
      • Extract variable
      • Wait
      • Database operations
        • Overview
        • MongoDB
        • Redis
        • Oracle Client
      • Using scripts
        • Overview
        • Postman scripts reference
        • Pre processor scripts
        • Post processor scripts
        • Public scripts
        • Calling other programming languages
        • Using JS libraries
        • Visualizing responses
        • Script examples
          • Assertion scripts
          • Using variables in scripts
          • Using scripts to modify request messages
          • Other examples
    • Dynamic values Modules
  • Mock API data
    • Overview
    • Smart mock
    • Custom mock
    • Mock priority sequence
    • Mock scripts
    • Cloud mock
    • Self-hosted runner mock
    • Mock language (Locales)
  • Automated tests
    • Overview
    • Test reports
    • Test scenarios
      • Create a test scenario
      • Pass data between requests
      • Flow control conditions
      • Import endpoints/endpoint cases from other projects
      • Sync data from endpoints/endpoint cases
      • Export test scenarios
    • Run test scenarios
      • Run a test scenario
      • Data-driven testing
      • Run test scenarios in batch
      • Scheduled tasks
      • Manage the runtime environment of APIs from other projects
    • Test APIs
      • Integration testing
      • Performance testing
      • End-to-end testing
      • Regression testing
    • Apidog CLI
      • Overview
      • Installing and running Apidog CLI
      • Apidog CLI Options
    • CI/CD
      • Overview
      • Integrate with Jenkins
      • Integration with Gitlab
  • Publish API Docs
    • Overview
    • API Technologies Supported
    • Quick share
    • View the API documentation
    • Publish docs sites
    • Folder tree settings
    • Custom layouts
    • Visibility settings
    • Endpoint SEO settings
    • Custom domain
    • Embedding values in document URLs
    • Documentation Search
    • Integrating Google Analytics with Doc Sites
    • CORS Proxy
    • API Versions
      • Overview
      • Create API versions
      • Publish API versions
      • Share endpoints with API versions
  • Send requests
    • Overview
    • gRPC
    • Use request proxy agents for debugging
    • SOAP/WebService
    • GraphQL
    • WebSocket
    • Socket.IO
    • SSE debugging
    • Create requests
      • Request History
      • Request basics
      • Parameters and body
      • Request headers
      • Request settings
      • HTTP/2
    • Authentication and authorization
      • Overview
      • CA and client certificates
      • Authorization types supported by Apidog
      • Digest Auth
      • OAuth 1.0
      • OAuth 2.0
      • Hawk Authentication
      • Kerberos
      • NTLM
      • Akamai EdgeGrid
    • Response and cookies
      • Overview
      • API response in Apidog
      • Create and send cookies
      • Debug requests
      • Save the request as an endpoint
  • Branches
    • Overview
    • Create a new sprint branch
    • Test APIs in a branch
    • Design API in a branch
    • Merge sprint branches
    • Manage sprint branches
  • Apidog MCP Server
    • Overview
    • Conntect API Specification within Apidog Project to AI via Apidog MCP Server
    • Conntect Online API Documentation Published by Apidog to AI via Apidog MCP Server
    • Conntect OpenAPI Files to AI via Apidog MCP Server
  • Best practices
    • How to handle API signatures
    • How to access OAuth 2.0 protected APIs
    • Apidog collaboration workflow
    • Managing authentication state in Apidog
  • Administration
    • Onboarding Checklist
      • Basic Concepts
      • Onboarding Guide
    • Managing Teams
      • Managing Teams
      • Managing Team Members
      • Member Roles & Permission Settings
      • Team Activities
      • Team Resources
        • General Runner
        • Team Variables
        • Request Proxy Agent
      • Real-time Collaborations
        • Team Collaboration
    • Managing Projects
      • Managing Projects
      • Managing Project Members
      • Notification Settings
      • Project Resources
        • Database Connection
    • Managing Organizations
      • Single Sign-On (SSO)
        • SSO Overview
        • Configure Microsoft Entra ID
        • Configure Okta
        • Configure SSO for an Organization
        • Managing user accounts
        • Mapping Groups to Teams
      • SCIM Provisioning
        • Intro to SCIM Provisioning
        • Microsoft Entra ID
        • Okta
      • Organization Resources
        • Self-hosted Runner
  • Billing
    • Overview
    • Credits
    • Unable to use credit cards?
    • Managing subscriptions
    • Upgrade plan
  • Add-ons
    • API Hub
    • Apidog Intellij IDEA plugin
    • Browser Extension
      • Chrome
      • Microsoft Edge
    • Request Proxy
      • Request proxy in Apidog web
      • Request proxy in shared docs
      • Request proxy in Apidog client
  • Account & preferences
    • Language settings
    • Data backup
    • Network proxy configuration
    • Hot keys
    • Updating Apidog
    • Generate OpenAPI access token
    • Deleting account
    • Account settings
  • References
    • API-Design First Approach
    • Apidog OpenAPI Specificaiton Extensions
    • JSONPath
    • XPath
    • Regular Expressions
    • JSON Schema
    • CSV File Format
    • Install Java Environment
    • Runner deployment environment
    • Apidog flavored Markdown
  • Apidog Europe
    • Apidog Europe
  • Support Center
  1. Mock API data

Custom mock

Apidog provides a powerful mock feature that allows you to simulate API responses with fine-grained control. This document introduces the two main ways to customize your mock data:
1.
Customize Specific Fields: Control certain fields in the mock response, with smart mock for other fields.
2.
Full response customization: Define the entire mock response with expectations (supports fixed, conditional, and dynamic responses).

Customize Specific Fields#

Sometimes, you may want to define specific values for certain fields in the response, while letting Apidog auto-generate (smart mock) the remaining fields. Apidog provides flexible ways to handle this:

How to Set Custom Field Values#

1. Directly Input Values#

Specify a fixed value directly in the endpoint spec’s mock field, and Apidog will always return this value for that field. All unspecified fields will use Apidog’s smart mock generation.
Example:
image.png

2. Use Faker.js Dynamic Values#

You can use Apidog’s dynamic values (based on Faker.js) to generate realistic random data. Use the syntax:
{{$category.method}}
Examples:
A random full name: {{$person.fullName}}, results like Rachel Wheeler
An email address: {{$internet.email}}, results like Arno.Huels33@yahoo.com
A product name: {{$commerce.productName}}, results like Elegant Plastic Bike
You can directly select items in the dropdown.
image.png

3. Use Faker Methods With Parameters#

You can pass parameters to dynamic value methods for more specialized data, following Apidog’s enhanced Faker.js syntax.
For example:
Generate an integer between 0 and 10,000:
{{$number.int(min=0,max=10000)}}
Generate a phone number in a readable style:
{{$phone.number(style='human')}}
Generate an integer that is a multiple of 3:
{{$number.int(multipleOf=3)}}
Pick a random element from an array:
{{$helpers.arrayElement(['red','blue','green'])}}
Generate a date within a range (custom formats supported):
{{$date.between(from='2024-01-01',to='2024-12-31',format='yyyy-MM-dd')}}
Explore the complete list of modules, methods, and their parameters in the Dynamic Values Modules documentation.

4. Concatenate Multiple Dynamic Expressions (Generate a Full Address Example)#

You can freely combine static text and multiple dynamic expressions to generate complex field values.
For example, to generate a realistic full address in one string, you can write:
{{$location.streetAddress}}, {{$location.city}}, {{$location.state}}, {{$location.zipCode}}, {{$location.country}}
This will output a result similar to:
"8507 Hudson Alley, Rochester, Wisconsin, 96512, United States"
Each part is dynamically generated, creating a unique and realistic address every time the mock API is called.
Mock locales
Apidog supports customizable mock locales, allowing you to generate dynamic test data in different languages and formats that match your target region or audience. To learn more about configuring mock locales, visit Mock language (Locales).

Customize the Entire Mock Response (Mock Expectations)#

If you need to return a specific or highly customized mock response, use "mock expectations." This gives you full control over what the mock service returns.

Setting a Mock Expectation#

Background#

image.png

Returning Fixed Data#

You can set an unconditional expectation to always return the same data.
Steps
1.
Click "New expectation".
2.
Add an expectation name. Leave the conditions blank.
3.
Fill in the Response data you want to return, then save.
4.
Copy and use the provided mock URL to access this endpoint.

Returning Conditional Data#

You can return different mock data based on request parameters. Apidog's mock expectations support parameter-based conditions.
Add multiple expectations with different conditions.
The mock engine matches incoming requests to these conditions (from top to bottom), returning the first matching expectation.
If no conditions match, Apidog falls back to the Mock method priority set in Project Settings > Feature Settings > Mock Settings.
Supported Condition Types
Query parameters
Path parameters
Header parameters
Cookie parameters
Body parameters (JSON only)
For body parameters, specify a JSON path to the property. Conditions are combined as an intersection (all must match).
Note
Body parameters support only JSON, not XML.
Parameter conditions cannot use {{variables}}.
If you use body parameters for expectation matching, the request body format must match the API spec (e.g., form-data, JSON, etc.).
You can also add IP address conditions to restrict responses to specific IPs.

Returning Dynamic Mock Data#

Mock expectations support dynamic, randomized data using Faker.js and Nunjucks syntax.
Example#
{
    "data": [
        {% for i in range(0, 20) %}
        {% if i>1 %},{% endif %}
        {
            "id": {{i}},
            "firstname": "{{$person.firstName}}",
            "lastname": "{{$person.lastName}}"
        }
        {% endfor %}
    ],
    "success": true
}
The above generates:
An array of 20 user objects (id = 0 to 19)
Each with randomly generated "firstname" and "lastname"
A constant "success": true
{{$...}} syntax invokes Faker.js to generate random values.
Nunjucks is used for loops ({% for ... %}) and logic.
{{i}} refers to a Nunjucks loop variable—not an Apidog variable.
Notes
Apidog uses {{$...}} for Faker.js expressions (not the native JS call syntax).
Faker.js (native): faker.person.firstName()
Apidog: {{$person.firstName}}
Apidog project/environment variables (like {{variable}}) are not available in mock expectations.
Full Faker.js and Nunjucks documentation: Faker.js, Nunjucks

More Features#

Custom Response Headers
You can add custom headers to a mock expectation, useful for simulating authentication, pagination, or any other API contract.
Advanced Response Properties
In the "More" tab inside mock expectations, you can set:
HTTP status code: Simulate error or special cases (default is 200).
Response delay: Simulate slow API responses by adding a delay (in milliseconds).
Enable/Disable Expectations
Toggle each expectation on/off separately for local and cloud mock environments from the expectation list.

Summary#

With Apidog custom mock, you can:
Mix specific mock values with auto-generated data for flexibility.
Define full fixed, conditional, or dynamic responses for comprehensive test scenarios.
Leverage Faker.js and Nunjucks to create powerful, realistic, and variable mock data.
Simulate headers, delays, status codes, and more!
Explore these features to create robust, high-fidelity API simulations that mirror your production APIs!
Modified at 2025-04-24 11:02:06
Previous
Smart mock
Next
Mock priority sequence
Built with