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 · 4 comments
Open

Unable to Capture Query Parameters #1330

atharva-campbooks opened this issue Aug 22, 2023 · 4 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.

@thejon07
Copy link

i want to work on this issue please assign me

@testgithubsonika
Copy link

@atharva-campbooks due to the use of JSON.stringify(arrayofQuery) in the query field of the request.
Instead of converting the query parameters to a JSON string, you should keep them as an array of objects,
[!IMPORTANT] - query: arrayofQuery,

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

3 participants