Mastering Postman: Built-In and Custom Dynamic Parameters in Postman

Whether you’re dealing with built-in or custom dynamic parameters, Postman provides robust tools to automate and simplify tedious aspects of API testing.

Postman has become an indispensable tool for developers, enabling them to efficiently debug and test APIs. Among its many features, the ability to handle dynamic parameters stands out as a crucial technique that can streamline development workflows and minimize repetitive tasks.

Postman.png

In this article, we will address a common challenge faced by developers: manually modifying parameters in API requests. While manual adjustment works, it can quickly become tedious and error-prone, especially for tests requiring multiple iterations. To solve this, we’ll explore Postman’s built-in dynamic parameters and walk through how to create custom dynamic parameters.

But before diving into this topic, let’s revisit three common scenarios where Postman really shines:

1. Handling multiple environments: Learn how to manage different environments in Postman in this detailed guide.

User Guide: How to Use Postman Environments
When using Postman to enhance API development efficiency, leveraging the Environment feature is essential. This article provides a thorough explanation of how to use Postman’s Environments functionality.


2. Achieving API chaining: See how Postman can link API requests seamlessly with techniques discussed here.

Mastering Postman: Implementing API Chaining with the JSON Extractor
In this article, we will take a hands-on approach to explore how to implement API chaining using the JSON extractor, a crucial technique in Postman that streamlines testing processes.
Mastering Postman: Implementing API Chaining with the Regex Extractor
In this article, we’ll explore how to use the Regex extractor in Postman for API chaining, enhancing automation and efficiency in API testing.


3. Dynamic input values: This is what we’ll focus on in today’s article—automating dynamic modification of API parameters.

Let’s jump in and see how to leverage Postman’s dynamic parameter features to solve the issue of manual modifications.

Built-In Dynamic Parameters in Postman

Dynamic Parameters.jpg

Postman has several built-in dynamic parameters that you can use out of the box. These parameters simplify tasks that involve generating random or time-sensitive data. Here are some examples:

  • {{$timestamp}}: Generates the current Unix timestamp (in milliseconds).
  • {{$randomInt}}: Generates a random integer between 0 and 1,000.
  • {{$guid}}: Generates a random GUID string.

Example Use Case: Avoiding "Username Already Exists" Errors

Imagine you’re working on the Create a New User API. If you repeatedly use a fixed username, such as echoapi, you’ll receive an error message:

{
    "error": 1,
    "msg": "Username already exists"
}
Username Already Exists.jpg

To handle this, you can append a built-in dynamic parameter to the username field. For example:

{
  "username": "echoapi{{$timestamp}}"
}

When you send the request, Postman will replace {{$timestamp}} with the current Unix timestamp, ensuring each request has a unique username. This approach saves you from manually modifying the username for each request and avoids conflicts caused by duplicate entries.

timestamp.jpg

Built-in dynamic parameters offer a quick way to generate random or unique values, making your tests more efficient, reliable, and automated.

Custom Dynamic Parameters in Postman

While Postman’s built-in dynamic parameters are incredibly helpful, some scenarios may require creating your own custom dynamic parameters. Let’s use the generating a timestamp scenario to demonstrate how to create and use custom dynamic parameters.

Step 1: Write a Pre-Request Script

Pre-request scripts are executed before sending an API request. To create a custom timestamp:

1. Navigate to the Pre-request Script section of your API request.

Pre-request Script.jpg

2. Write a small script to generate the current timestamp:

var time = Date.now();
pm.globals.set("time", time);
  • Date.now() generates the current Unix timestamp.
  • pm.globals.set saves the generated value as a global variable (time) that can be accessed in any API request.
timestamp.jpg
Basic Postman Script Examples. Developers You Should Know
Enhance API development by grasping Postman scripts! By scripting your API requests, you can enhance efficiency and elevate the functionality of your API. Postman Scripts, crafted in JavaScript, empower users to automate intricate workflows and enhance API testing. This article will delve into the realm of Postman script examples, examining

Step 2: Use the Custom Parameter in the Request

Now, modify the username field in the request payload to use the dynamically generated timestamp. For example:

{
  "username": "echoapi{{time}}"
}
time.jpg

When you send the request, Postman will replace {{time}} with the value generated in the pre-request script. For instance:

{
    "error": 0,
    "msg": "ok",
    "user": {
        "id": 1749,
        "username": "echoapi1737016627293",
        "firstName": "Echo",
        "lastName": "Api",
        "email": "support@echoapi.com",
        "password": "12345",
        "phone": "",
        "userStatus": 0
    }
}
Custom Parameter.jpg

This method allows you to create dynamic parameters tailored to your specific testing needs, extending Postman’s flexibility even further.

How to Configure Global and Folder-Level Request Parameters in Postman?
When debugging a large number of APIs, there are many parameters that are commonly used, such as tokens. There are also many parameters that are common within a specific directory. We don’t want to repeatedly copy and paste the same parameter into different APIs.Now EchoAPI brings new change.

Conclusion

Whether you’re dealing with built-in or custom dynamic parameters, Postman provides robust tools to automate and simplify tedious aspects of API testing. Using built-in dynamic parameters (such as {{$timestamp}}, {{$randomInt}}, and {{$guid}}) is perfect for most use cases, while custom dynamic parameters enable even greater control and versatility for more complex scenarios.

By leveraging these features, you can eliminate repetitive manual modifications, reduce errors, and streamline your testing workflow. As a developer, mastering dynamic parameters is an essential skill that will save you time and increase the reliability of your tests.

Postman’s versatility and efficiency come to life when you use these tools strategically—so start exploring dynamic parameters today and see how much smoother your testing process becomes!