Skip to content

Instantly share code, notes, and snippets.

@rajbharath
Created June 26, 2015 13:11
Show Gist options
  • Save rajbharath/5f37827031692845cf87 to your computer and use it in GitHub Desktop.
Save rajbharath/5f37827031692845cf87 to your computer and use it in GitHub Desktop.
How to create UUID in postman rest client
{{$guid}}
the above variable will generate UUID in Postman Rest Client
Sample request is below
========================
{
"user":{
"id":"{{$guid}}"
}
}
@mordi34
Copy link

mordi34 commented Aug 1, 2016

Thanks for this! And note that (as seen here: postmanlabs/postman-app-support#851) {{$guid}} will always return the same GUID/UUID for a given request

@brucedeen
Copy link

How do you create a v4 UUID, the format isn't followed by the {{$guid}}. The UUID v4 format should be xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B

@RangerDan
Copy link

Found this on Stack Overflow and tested in most recent update on Linux.

In your Pre-request Script, add this to any test you need a fresh v4 UUID in:
postman.setGlobalVariable("v4uuid", 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); }));

Then call this in your post body, headers, wherever it's needed:
{{v4uuid}}

@AlexGrafe
Copy link

By now (2018-06-01) you can simply do the following: var uuid = require('uuid'); var myUUID = uuid.v4();.

@michelepatrassi
Copy link

you can also use their dynamic variables: https://learning.getpostman.com/docs/variables_list/

@userlerueda
Copy link

Does anyone know which version of UUID this {{randomUUID}} generates ?

@letaoana
Copy link

letaoana commented Jan 5, 2020

Much thanks @rajbharath! 👍

@bbezanson
Copy link

@creative-singh
Copy link

Does anyone know which version of UUID this {{randomUUID}} generates ?

v4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment