Skip to content

Unable to Capture Query Parameters #1330

@atharva-campbooks

Description

@atharva-campbooks

Hello Team,
We are trying to run the following code to generate postman collection automatically. We are expecting to get request body and request parameters to get added automatically but someone in the final JSON, the parameters are empty.

Can someone point in case we are missing out something?

Thanks in advance!!

    let basepath = "http://localhost:3001/api/v1/health" + req.route.path;
    const requestPayload = req.body;

    const arrayofQuery = Object.keys(req.query).map((key) => {
      return {
        key: key,
        value: req.query[key],
      };
    });

    console.log("Query Params", arrayofQuery ) //here query is printed as array of object, as expeted.

    const postmanCollection = new Collection({
      info: {
        name: "Sample Postman collection",
      },
      item: [],
    });

    const postmanRequest = new Item({
      name: req.route.path,
      request: {
        url: basepath,
        method: req.method,
        query: JSON.stringify(arrayofQuery),
        body: {
          mode: "raw",
          raw: JSON.stringify(requestPayload),
          options: {
            raw: {
              language: "json",
            },
          },
        },
        auth: null,
      },
      event: [],
    });
    console.log("Final Payload", postmanRequest) //here query is printed as []
    postmanCollection.items.add(postmanRequest);
    const collectionJSON = postmanCollection.toJSON();
 
    fs.writeFile(
      "./collection.json",
      JSON.stringify(collectionJSON, null, 2),
      (err) => {
        if (err) {
          console.log(err);
        }
        console.log("File saved");
      }
    );
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions