0

How could I add an automatic environmental variable in Postman based on a value which is appearing in the endpoint response in the array?

In the example below, I would like to use the "id3" value and save it as a dynamic variable.

 {
 "test": 123,
 "test2": [],
 "test3": [
 {
 "id": 0,
 "id2": 4554336,
 "id3": 30,
 "id4": 0
 }
 ]
 }

I thought it will be simple as:

let jsonData = pm.response.json();
pm.environment.set("test_name", jsonData.test3.id);

but this set up is saving the variable with a null value.

Daniel Widdis
9,30013 gold badges50 silver badges69 bronze badges
asked Dec 7, 2020 at 14:40

1 Answer 1

1
 let jsonData = pm.response.json(); 
pm.environment.set("test_name", jsonData.test3[0].id3);

test3 is an array so you have to get the first object and then id3

answered Dec 7, 2020 at 15:53
1
  • @wer could you accept the answer by clicking the tick sign near to the answer Commented Dec 8, 2020 at 13:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.