I am using Postman and I need to retrieve JSON data. My goal is to retrieve it either from a local file on my computer or from the internet. However, I am facing difficulties in both cases.
Is it possible to retrieve JSON data from a local file in Postman? If yes, then how can I achieve this? I have tried using the fs module in the Postman Sandbox environment but I keep getting an error that fs.readFileSync is not a function.
If it is not possible to retrieve JSON data from a local file, then can I retrieve it from the internet instead? If yes, then how can I do this? I would appreciate it if you could provide an example or solution for this as well.
My Tests code:
const fs = require('fs');
let rawdata = fs.readFileSync('path/to/file.json');
let jsonData = JSON.parse(rawdata);
console.log(jsonData);
You can however, use the collection runner which allow you to iterate over a JSON file or CSV file.
If you don’t want to iterate over the JSON file per se, and just want an object with the JSON contents, then you can add the JSON into a single cell in a CSV file and then retrieve that using the collection runner. (This should work in Newman as well). It’s a workaround of sorts.
Retrieving the content from the Internet should work though as that should be just another API call. You haven’t really explained what difficulties are are having in that respect.
I would recommend starting with the “Galaxy APIs 101” and “Galaxy Testing and Automation” courses. (The Galaxy APIs has an error on the final submission, which I hope will be fixed at some point in the near future).
Finally, the following will explain how to set and use variables.