Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit Characters returned in Header within Postman Environment

I'm working with an API set that requires a Session Key to be pulled down and used in the Authorization Header for subsequent calls to the service. The value to be added to the Header is X-CardConnect-SessionKey See below for example. The first 20-digits, everything in front of the semi-colon, needs to be included in future calls to the service once obtained.

Postman Image

This is what I'm getting -->

X-CardConnect-SessionKey →9ffcd7dc737f4b9fbdccb299b9c55f4b;expires=2017-12-28T20:54:19.652Z

This is what I need:

X-CardConnect-SessionKey →9ffcd7dc737f4b9fbdccb299b9c55f4b

In Postman I am using the following to parse the Session Key value into my environment:

var data = responseHeaders
postman.setEnvironmentVariable ("X-CardConnect-SessionKey", data["X-
CardConnect-SessionKey"])

Naturally, the full string is inserted into the Environment when I only need the first 20 digits. Is there a way to limit the character limit so that only the first 20 digits are returned?

Thanks!

like image 604
Robert Cowie Avatar asked Apr 20 '26 12:04

Robert Cowie


1 Answers

You can split the value using native JS or look at using one of the Lodash _.split() functions.

var data = "9ffcd7dc737f4b9fbdccb299b9c55f4b;expires=2017-12-
28T20:54:19.652Z"

postman.setEnvironmentVariable("test", data.split(';',1)); 

Or for what you need something along these lines:

var data = responseHeaders
postman.setEnvironmentVariable("X-CardConnect-SessionKey", data.X-
CardConnect-SessionKey.split(';',1))
like image 154
Danny Dainton Avatar answered Apr 22 '26 00:04

Danny Dainton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!