by joe.pesch
9. August 2019 08:14
First, create an environment variable called responseData, with the value [].
Then, add the following code under 'Tests' in Builder. Postman environment variables are intended to be used as string, so we will parse the object then push the JSON responses from the API into the object array.
var jsonData = JSON.parse(responseBody); var old = pm.environment.get("responseData"); old = JSON.parse(old); // filter jsonData if needed
old.push(jsonData); old = JSON.stringify(old); pm.environment.set("responseData", old); console.log(pm.environment.get("responseData")); Now you can retrieve a nested JSON object with all the response data included by viewing the environment variables value (see example below).
Warning: you must reset the responseData value as [] after every use of Collection Runner in order to avoid keeping data from previous runs.
02466818-1c8c-43ce-8657-f61ad70a2fd2|1|5.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04
Tags: