-
-
Save rajbharath/5f37827031692845cf87 to your computer and use it in GitHub Desktop.
{{$guid}} | |
the above variable will generate UUID in Postman Rest Client | |
Sample request is below | |
======================== | |
{ | |
"user":{ | |
"id":"{{$guid}}" | |
} | |
} |
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
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}}
By now (2018-06-01) you can simply do the following: var uuid = require('uuid'); var myUUID = uuid.v4();
.
you can also use their dynamic variables: https://learning.getpostman.com/docs/variables_list/
Does anyone know which version of UUID this {{randomUUID}} generates ?
Much thanks @rajbharath! 👍
you can also use their dynamic variables: https://learning.getpostman.com/docs/variables_list/
This is now located here: https://learning.getpostman.com/docs/postman/variables-and-environments/variables-list/
Does anyone know which version of UUID this {{randomUUID}} generates ?
v4
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