0

i have the below

let bodyData = pm.response.json()

let country = bodyData[0].Country

console.log(country)

pm.environment.set("country", country)

but i want to set multiple variables. I have around 8 different variables in my environment and i tried the below but it doesnt work

let bodyData = pm.response.json()

let country = bodyData[0].Country
let postcode = bodyData[0].Postcode

console.log(country,postcode)

pm.environment.set("country","postcode", country, postcode)

any help appreciated

FreshX
  • 57
  • 2
  • 10
  • Does this answer your question? [Postman: Can i save JSON objects to environment variable so as to chain it for another request?](https://stackoverflow.com/questions/41479494/postman-can-i-save-json-objects-to-environment-variable-so-as-to-chain-it-for-a) – Henke Feb 28 '21 at 06:49

1 Answers1

0

You would need to create separate .set() statements to capture and reuse the different variables in other requests.

pm.environment.set("country", country)
pm.environment.set("postcode", postcode)
Danny Dainton
  • 23,069
  • 6
  • 67
  • 80
  • for a sendRequest format, this worked for me (finally): ```function (err, res) { let response = res.json(); pm.environment.set("country", response.country); pm.environment.set("postcode",response.postcode); });``` (sorry for the ugly format. I can't figure this out yet for comments) – Kreidol Sep 30 '21 at 01:16