1

I am running the postman runner for a GET request, that uses a data file to iterate through values for a query parameter, such as a user's email. I'd like to store the response for each iteration in a single JSON or data file to match the responses to each email iteration.

Could someone help with how I might approach this?

  • 1
    Welcome to So, Please take a look at [this](https://stackoverflow.com/help/how-to-ask) to ask a better question. please share some research or code you tested before – sajjad rezaei Jan 16 '22 at 19:31
  • Answered here: https://stackoverflow.com/a/71899537/6834435 | Regarding matching, you don't have to save responses, see https://learning.postman.com/docs/writing-scripts/test-scripts/ – N. M. Aug 26 '22 at 12:42
  • Does this answer your question? [Bulk POST/PUT API requests using POSTMAN or any other means](https://stackoverflow.com/questions/56448021/bulk-post-put-api-requests-using-postman-or-any-other-means) – Christian Baumann Aug 27 '22 at 06:06

1 Answers1

0

A simple solution to get the Postman runner responses in a single JSON/CSV format:

  1. Create a collection and add the APIs to the collection.
  2. In the 'Tests' tab, add a JavaScript script to store the API response with specific values into environment variables. enter image description here

let responses = pm.collectionVariables.get('collectionResponses');
if(responses) {
  responses = JSON.parse(responses);
} else {
  responses = [];
}

responses.push({link : pm.response.json().poster,Id:pm.response.json().id});
pm.collectionVariables.set('collectionResponses', JSON.stringify(responses));


console.log(JSON.stringify(responses));

The above code will save the reponse into 'collectionResponses' variable.

  1. Run the runner with the APIs.
  2. After completion, go to the collection, right-click, and select 'Edit.'
  3. Navigate to the 'Variables' tab and read the variable values.
  4. If you need the data in CSV format, copy the JSON responses and use an online tool to convert them to CSV.