I have a json file, where I am using this json I receive from postman rest api -
{
"info": {
"_postman_id": "ac278c9e-d1d7-4a50-8d15-134de3de5e80",
"name": "Types",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [{
"name": "get",
"id": "0bf436da-794b-45c7-adf5-32f0e7a70105",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"userId\": {{userId}},\r\n \"projectId\": {{projectId}}\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:9090/types/get",
"protocol": "http",
"host": ["localhost"],
"port": "9090",
"path": ["types", "get"]
}
},
"response": []
}]
}
Then I am using this code to create a collection object and iterate over items -
let Collection = require('postman-collection').Collection;
let collObj = JSON.stringify(fs.readFileSync('postmanapi.json').toString());
const collection = new Collection(collObj);
console.log(collection);
No matter what I try, I always end up with a collection object which has empty item object
{"item":[],"event":[],"variable":[],"info":{"_postman_id":"f165a325-ba8a-4117-8fd3-c5e3e68369e1","schema":"https://schema.getpostman.com/json/collection/v2.1.0/collection.json"}}
How do I solve this? Thanks. Is this a version issue? I am using -
"postman-collection": "^4.1.0"