Dynamic GUID: How to Dynamically Generate & Use GUID in Postman

Backend Pro

 It's quite common to come across a situation where you have to generate the GUID dynamically and add it to the request body or Query parameter or Request header. 

For example, you want to run a request multiple times and each time you want to pass a different GUID in request body. 

This can be done easily in postman without writing single line of code. Postman has a inbuilt variable for this purpose i.e $guid. you just need to wrap it inside double curly braces i.e {{$guid}} 

Let's have a look at few requests where we can leverage $guid.

$guid as Query parameter

Here, I am using $guid as part of query parameter and you can also verify the actual value of guid in console. The GUID that is generated after executing the script is 6976eca-c0fd-4fd7-a819-05dedbeae3cd

$guid in Request Body

Here, I am using $guid as part of the Request Body and in console you can see generated GUID. This time the generated GUID is 61b4ff2a-062c-442d-8276-ad61a6e10894 which different from the previous section.

$guid in Request Headers

$guid can also be used in Request Headers similar to Request Body & Query Parameters. The usage is same i.e ${{guid}}.

Once you have executed the request, open the console and check Request Headers and you can see the actual guid. 


Even you can generate GUID by writing a script, but for most of the cases it is not required. In my opinion, this is the simple, easy and most effective. You just have to remember the variable name i.e $guid and how to use it i.e {{$guid}}.
Tags

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Check Now
Accept !