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.

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!
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With