Skip to content
New issue

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

raw is missing during new Item create in postman collection #1211

Open
pipaliyachirag opened this issue Aug 9, 2021 · 0 comments
Open

raw is missing during new Item create in postman collection #1211

pipaliyachirag opened this issue Aug 9, 2021 · 0 comments

Comments

@pipaliyachirag
Copy link

pipaliyachirag commented Aug 9, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant