We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code:
const fs = require("fs"); const { Collection,Url,Header,Item } = require('postman-collection'); (async ()=>{ const collection = new Collection({ info: { name:"shadow", }, }) const rawHeaderString = 'Authorization:\nContent-Type:application/json\ncache-control:no-cache\n'; // Parsing string to postman compatible format const rawHeaders = Header.parse(rawHeaderString); // Generate headers const requestHeader = rawHeaders.map((h) => new Header(h)); // Request body const requestPayload = { key1: 'value1', key2: 'value2', key3: 'value3' }; collection.items.add(new Item({ name:"item1", request:{ url:Url.parse("http://localhost:3000/api/v1/users"), method:"post", header:requestHeader, body: { mode: 'raw', raw: JSON.stringify(requestPayload), }, } })) const collectionJSON = collection.toJSON(); fs.writeFile('./collection.json', JSON.stringify(collectionJSON,null,2), (err) => { if (err) { console.log(err); } console.log('File saved'); }); })();
expected output:
{ "item": [ { "id": "69e1560e-b51f-498f-b3f5-f0b802fe6c0e", "name": "item1", "request": { "url": { "raw": "http://localhost:3000/api/v1/users", "protocol": "http", "host": [ "localhost" ], "port": "3000", "path": [ "api", "v1", "users" ] }, "header": [ { "key": "Authorization", "value": "" }, { "key": "Content-Type", "value": "application/json" }, { "key": "cache-control", "value": "no-cache" } ], "method": "POST", "body": { "mode": "raw", "raw": "{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}" } }, "response": [], "event": [] } ], "event": [], "variable": [], "info": { "_postman_id": "0cfa6f5f-9b10-40c8-b539-d724b9360c2a", "name": "shadow", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" } }
but getting:
{ "item": [ { "id": "6cac2a38-a8fe-471c-bf4c-1e22e4908fef", "name": "item1", "request": { "url": { "protocol": "http", "port": "3000", "path": [ "api", "v1", "users" ], "host": [ "localhost" ], "query": [], "variable": [] }, "header": [ { "key": "Authorization", "value": "" }, { "key": "Content-Type", "value": "application/json" }, { "key": "cache-control", "value": "no-cache" } ], "method": "POST", "body": { "mode": "raw", "raw": "{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}" } }, "response": [], "event": [] } ], "event": [], "variable": [], "info": { "_postman_id": "141fe14f-9c09-421b-83d1-37e321569bd1", "name": "shadow", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" } }
raw field is missing in url object during export.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
code:
expected output:
but getting:
raw field is missing in url object during export.
The text was updated successfully, but these errors were encountered: