I'm chaining several requests to simulate an end to end scenario in Postman.
I have an array of values which was returned back from the first request.I've set the array as an environment variable so that it can be accessed by other subsequent requests in my collection.
pm.environment.set("travArray", travArray);
The console output of the travArray
looks like:
0:"d4faf286-ab68-448b-87cb-ad6a7030bc57"1:"2e21ab1f-25be-49ab-a984-db529022cf0f"2:"9a1d942c-4048-48a7-acfc-7a1c9563c528"
Next, I'm trying to post a JSON request with each of these indexed values.In the Body (raw) request it looks like this:
"travelers": [ {"id": "{{travArray[0]}}","firstName": "teaaf","lastName": "fadfadsfads","travelerType": "ADULT" }, {"id": "{{travArray[1]}}","firstName": "sdfsfsdf","lastName": "sdfsfsd","travelerType": "ADULT" }, {"id": "{{travArray[2]}}","firstName": "sdfsdf","lastName": "sdfsfsdf","travelerType": "ADULT" }],
But using this syntax {{travArray[1]}}
fails to parse the actual value when the raw request is posted to the API endpoint.
Interestingly, when I just use {{travArray}
- without the index notation, the entire contents of the array is sent.
Example output:
id:"d4faf286-ab68-448b-87cb-ad6a7030bc57,2e21ab1f-25be-49ab-a984-db529022cf0f,9a1d942c-4048-48a7-acfc-7a1c9563c528"firstName:"teaaf"lastName:"fadfadsfads"travelerType:"ADULT"
Can someone tell me how to parse index value of the array in the JSON body request?