Unanswered question

Parse value form a JSON message, and set a cookie and a header using the value

I am sure there is an easy enough way to do what I need.

After successful login, the authentication token from the server arrives in the body of response wrapped into a JSON message. It looks like this:


I need to parse that "eyJ0e...........UdI" string, and do 2 things with it:

1. Ensure that every request from this point forward (until virtual user logs out) has a header:

Authorization: Bearer eyJ0e.......UdI

2. Set 2 cookies: one to the same value as above, and another using the user name used during login.

Based on some research I have performed in the help system, it appears I should be using the JavaScript API to achieve this. Is this correct?

If so, I could use a bit of help with determining which JS calls to make in order to:
a. parse the token from the JSON message
b. set the header for every request going forward
c. set cookies
d. unset the header from (b) once user has logged out

Any ideas?


My progress so far:
a. I have followed the steps in NeoLoad documentation, and created a Variable Extractor. I parse into variable called token, from the body of the response.

Remaining parts:
b, c, and d.

onTy T.
onTy T.

onTy T.

6 / 100


In your recorded request, under the requests header tab, you can replace your recorded value for your Authorization Bearer header by your variable extractor name. You can use the search and request feature to do that. You should get something like this: Authorization: Bearer ${MyVariableExtractor}

Why do you need to set your cookies? If the cookies are set by the server NeoLoad automatically handles them. It's only necessary to manually handle them when it's client cookies.

also why do you need to unset your Authorization header? If your whole script is inside the Actions container all the user context (cookies, cache, variables) will be reset.