Stupid postman tricks

First the technology. RESTful calls are actually pretty cool. It is neat to simply send off a GET or POST message and extract or update the server with vital information. I am not going to write up a long article, well at this point anyway, describing RESTful calls.

Due to the flexibility and function of these calls there are a lot of tools and systems that make use of them. One such tool is Postman. This is a perfect tool for testing your RESTful calls on your servers. This might be during testing or it could be during development.


I was tasked with setting up some performance tests in another tool and my specification was a Postman script. You cannot really ask for a better specification than something that almost works like a finished program.

The only problem was that I had to run a few different steps and one of the steps required value from the previous step. This is actually almost trivial in Postman but the problem was I needed both the name and the value.  The source code that I had needed parse looked like this.

<input type="hidden" name="xsrf_CppTDEqKjryFYA9agpaloQ" value="LugLnMWKGWyiZD64jwys4g">

I need to pass back a variable called xsrf_CppTDEqKjryFYA9agpaloQ with the value LugLnMWKGWyiZD64jwys4g in the next postman step.

The good news is that postman uses java script as its scripting language.  This allows you to do plenty of interesting things when testing response values.  In my case I decided to use java script to parse the login page that is retrieved and then essentially an inelegant  search through the text for these values.

mysplits=data.split(” “);

var idx;
var valueidx=-1;
var cnt=mysplits.length;

for (idx=0; idx < cnt; idx++)
var search = mysplits[idx].substr(0,10);
if (search == searchname)
var pieces=mysplits[idx].split(“\””);

if (valueidx == idx)
var pieces=mysplits[idx].split(“\””);

This isn’t the type of code you would want to use for any production solutions but it is a fun little hack to assist during development.

This entry was posted in programming. Bookmark the permalink.