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

Unable to Capture Query Parameters #1330

Open
atharva-campbooks opened this issue Aug 22, 2023 · 2 comments
Open

Unable to Capture Query Parameters #1330

atharva-campbooks opened this issue Aug 22, 2023 · 2 comments

Comments

@atharva-campbooks
Copy link

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");
      }
    );
    
@atharva-campbooks
Copy link
Author

@atharvaunde

@testgithubsonika
Copy link

I would love to work on this issue so please assign me.

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

2 participants