How to provide expected JSON (response) using external text file in Postman

747 views Asked by At

I am making a collection where after hitting each API, I need to validate the response (in JSON) against my expected JSON which I have extracted after manually hitting the API first. I already know that I can pass this expected JSON as any other data variable from the CSV but the challenge is:

  1. The expected JSON is very large, and I have to do this for multiple APIs in the collection across multiple iterations
  2. The csv becomes VERY HEAVY and hard to maintain for any changes I need to make as its very tough to recognize where the JSON ended (I hope you can imagine).
  3. I want to use the same expected JSON across multiple collections, so I cannot "reuse" the same JSON and I am forced to write it everywhere, making it a maintenance nightmare.

I am looking for a way by which I can store the expected JSON in an external text file and a mechanism to provide the name/path of the txt file in the data.csv so as to centralize the expected JSONs.

1

There are 1 answers

0
Christian Baumann On

It's not possible to directly work with local files in Postman.

What you can do is to setup a (local) server, that you send a request to, and the response would contain your expected JSON, which you then can process in Postman.

For writing files to your local file system it's described here: https://blog.postman.com/write-to-your-local-file-system-using-a-postman-collection/ You could modify this for reading files.