How do you save an HTTP request result to a “user defined variable” config element?

38 views
Skip to first unread message

Pieter JJ

unread,
Jul 1, 2024, 4:43:40 PM (3 days ago) Jul 1
to JMeter Forum
I’m new to Jmeter and all help will be greatly appreciated. (Various websites, courses and searches were done over the last few days)
If you may please help with the following as I see it as a solution:
1) the response of the 1st API is a token
2) the token has to be base64  
         (BeanShell PostProcessor used from an example on the web)
3) then save the answer to a variable called “X-AUTH-TOKEN” in the 
        “User Define  Variables” config element, part of the top level under “Test Plan”
4) the “X-AUTH-TOKEN” variable has to be used in the Header of all other APIs

-> Q: please help with how to save the value of (2) in the “X-AUTH-TOKEN” ??
-> other solutions will also be appreciated
Test -  - 2024-07-01 006.jpg

DT

unread,
Jul 2, 2024, 5:13:28 AM (3 days ago) Jul 2
to JMeter Forum
User Defined Variables is used for creating an initial set of variables.

If you extract the token using JSON Extractor - just use X-AUTH-TOKEN reference name.

If you need to convert it to base64 additionally you can use JSR223 PostProcessor with the following Groovy code:

vars.put('X-AUTH-TOKEN',vars.get('X-AUTH-TOKEN').getBytes().encodeBase64().toString())

Then you can use HTTP Header Manager to set the token:

Untitled.jpg

pieterj

unread,
Jul 2, 2024, 3:04:26 PM (3 days ago) Jul 2
to JMeter Forum

Thank you, DT, for your assistance! Your solution is perfect, and I am grateful for your help.

Reply all
Reply to author
Forward
0 new messages