3

I'm trying to import a list of curl requests into a Postman collection.

With one single url i have no problem with import:

  • i go to import→paste raw text,
  • paste an url like curl -X GET 'https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=gesundbrunnen&inputtype=textquery&fields=formatted_address',
  • and it is imported like a charm.

But if i try the same game with two urls, i get an error

Error while importing Curl: Only the URL can be provided without an option preceding it. All other inputs must be specified via options.

What means the error, and how can i import multiple curl commands into Postman?

ps: A question beside the topic: maybe there are the ways to import multiple requests (GET/POST) and run them at once automatically, beside of Postman?

Evgeniy
  • 2,337
  • 2
  • 28
  • 68
  • have you had a look at this? https://community.getpostman.com/t/import-multiple-curl-into-postman/6785/4?u=arlemi – Arlemi Nov 07 '19 at 14:59

3 Answers3

2

This guy says you can write a script with curl-to-postman. I havn't tried but hope it helps.

Mossmyr
  • 909
  • 2
  • 10
  • 26
  • Please, when answering a question, dont post links... they will become obsolete or plainly dissapear quickly. Post your answer here, so that another user may see how to fix the issue, and not go somewhere else (that may redirect them further) – Bonatti Jun 17 '21 at 12:07
1

Try this way:

  • Put all of your cUrls into a file, each in a line
  • use "split" or other tools to split the file into multiple files, each line in a file (for split: split yourfile -l 1)
  • import them through postman's import button
efinal
  • 191
  • 1
  • 5
0

There are two available resource that can be combined to achieve this task.

  1. curl-to-postman module
  2. postman-collection sdk module

Thanks to bhargavkaranam, who has already written a script combining these modules. https://github.com/bhargavkaranam/multiple-curl-to-postman

postman-collection sdk module usage

convertToCollection(curlRequests, (err, collection) => {
  if (err) {
    console.log('Error occurred', err);

    process.exit(1);
  }

  let postmanCollection = collection.toJSON();

  fs.writeFile('Postman-Collection.json', JSON.stringify(postmanCollection, null, 4), (err) => {
    if (err) {
      console.log('Error writing to file', err);
    }

    console.log(JSON.stringify(postmanCollection, null, 4));
  });
});

curl-to-postman module usage

const curlToPostman = require('curl-to-postmanv2'),
  Collection = require('postman-collection').Collection;

module.exports = {
  convertToCollection: async function (curlRequests, cb) {
    if (!curlRequests) {
      console.log('No curl requests supplied!');
    
      process.exit(1);
    }

    let collection = new Collection();
    
    Promise.all(curlRequests.map((curl) => {
      return new Promise((resolve, reject) => {
        curlToPostman.convert({ type: 'string', data: curl }, (err, result) => {
          if (err) {
            return reject(err);
          }
    
          collection.items.add({ name: result.output[0] && result.output[0].data.name, request: result.output[0] && result.output[0].data });
    
          return resolve();
        });
      });
    }))
      .then(() => {
        return cb(null, collection);
      })
      .catch(cb);
  }
}