Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 512
Maddy Avatar asked Oct 26 '19 14:10

Maddy


People also ask

How do I get the string value of a Postman?

You could take a look at the . split() JS method to get that part of the string. This will create a new array of values based on the separator provided. Then you would need to specify the item you want, this will be zero-indexed so 0 would be the first item.

How do I view Postman header responses?

use postman. getResponseHeader in test collection to get header value. If the header value returned from server is as following. The value postman.

How do you check a response body in the Postman?

Go to the Tests tab on the request page. Now write the tests for validating the GET request: Let us consider an example for writing a test to this GET request, we have to check the response code is 200, and check the response body has the first name “Janet” present. tests[“Validate Status Code”] =responseCode.


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

like image 136
Danny Dainton Avatar answered Sep 20 '22 22:09

Danny Dainton