How to extract a particular string value from response header in postman?

Viewed 3059

I have below string and want to extract the value of code. I used split function but which runs fine in postman but when i execute same in newman it gives error.

header1=https://debugger.com/ultradebugcode?code=EgxIZAAU3uHVt20pc9qqpv-xNcAWxitpB0vgMiulNLG2hkysukmjR04Fxxnuz9Yb&state=ABC

I want to extract the value of code. which in this case is

EgxIZAAU3uHVt20pc9qqpv-xNcAWxitpB0vgMiulNLG2hkysukmjR04Fxxnuz9Yb

the code i am using is

    var str= pm.response.headers.get('header1');
    var str1= str.split('code=', 2)[1];
    var code= str1.split('&', 2)[0]; // get the code

It worked fine in postman but why newman is giving error here?

1 Answers

This worked for me:

let str = pm.response.headers.get("header1").split("code=")[1]

console.log(str.split("&")[0])

enter image description here

Related