In POSTMAN how do i get substring of response header item?

user1559625 picture user1559625 · Jan 8, 2019 · Viewed 7.7k times · Source

I am using postman to get response header value like below:

var data = postman.getResponseHeader("Location") . //value is "http://aaa/bbb" for example 

I can print the value via console.log(data) easily.

However, what I really want is "bbb". So I need some substring() type of function. And apparently 'data' is not a javascript string type, because data.substring(10) for example always return null.

Does anyone what i need to do in this case?

If any postman API doc existing that explains this?

Answer

Bhoomi picture Bhoomi · Jan 8, 2019

You can set an environment variable in postman. try something like

var data = JSON.parse(postman.getResponseHeader("Location"));
postman.setEnvironmentVariable("dataObj", data.href.substring(10));