Using request body filled from csv file as variable

I have a request:

I want to fill variables {{username}}, {{user-ip}}, {{user-hostname}} using csv file which I run.
After running it Request body json is correctly filled with data

Now I want to take this
“username” : *****
“user-ip”: *****
and put it into my request as variables in brackets {{ }}

I’d tried this script but I get this error…

Can you help me with this?

First of all the response in the last screenshot is XML, not JSON, so you will need to parse it using pm.rseponse.text() instead of pm.response.json().

However, I’m not really understanding what you are doing with the variables.

You seem to be mixing request and response elements.

Your initial request is using query parameters


But your first screenshot from the collection runner is is showing a JSON body?

Can you share a screenshot of the actual request itself. Including the body and params tab and any scripts you have?

It can’t be query parameters and a JSON body. Its either one or the other.

In the final screenshot, it looks like you are trying to set the userName in the tests tab. The tests tab runs after the request. If the request needs the userName, then logically this can’t be correct.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.