Import multiple CURL requests into collection

How can i import multiple CURL requests? If i go to import, than to “paste raw text” and paste one url like curl -X GET 'https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=gesundbrunnen&inputtype=textquery&fields=formatted_address', than the request is imported. But if i try to do the same with more then one url at once, i get an error like Error while importing Curl: Only the URL can be provided without an option preceding it. All other inputs must be specified via options.

What i’m doing wrong? What can i do to import multiple requests and then run them at once as collection?

Hi @chilly_bang,
Welcome to the community! :wave:

Right now, the importer does not support importing multiple cURL requests at once. However, to unblock you, I have written a small script that makes use of our open-source importer (GitHub - postmanlabs/curl-to-postman: Converts curl requests to Postman Collection v2 request objects) and the Collection SDK (GitHub - postmanlabs/postman-collection: Javascript module that allows a developer to work with Postman Collections) to achive this.

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

let curlRequests = [
  `curl -X GET \
  'http://postman-echo.get?foo=bar&batman=joker' \
  -H 'Postman-Token: 1a88e7fd-5b67-434c-aaf8-90ed9bfc3d46' \
  -H 'cache-control: no-cache' \
  -H 'content: application/json'`,

  `curl -X POST \
  http://postman-echo.com/post \
  -H 'Content-Type: application/json' \
  -H 'Postman-Token: e6a3a3d7-4a55-4dd8-a080-6ad7e425a9b0' \
  -H 'cache-control: no-cache' \
  -d '{
	a: 1,
	b: 2
  }'`],
  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(() => {
    console.log(JSON.stringify(collection.toJSON()));
  })
  .catch((err) => {
    console.log(err);
  });

You can replace the cURL requests in the array above with the cURL requests you want. You can play around with the code here RunKit

This will generate (log) a collection JSON that you can import to Postman directly that will have all the requests.

4 Likes

Hello,
Can we put each curl request on one line even when it has data associated with it like in POST requests?
Are the Postman-Token and cache control headers required for the converter to work properly?

Best Regards,
Thanks for your time.
Alexandre ELISÉ
Web developer and Joomla! specialist

No, that was just an example. You can remove all the headers if you don’t need them.

Here is my version of your code with some data. I tried to make it work on nodejs for mac os catalina but it tells me the same error as the previous person mentioned.
Here is the code. Any enlightment from you would be more than appreciated.

const curlToPostman = require('curl-to-postmanv2'),

Collection = require(‘postman-collection’).Collection;

let curlRequests = [curl -X GET 'https://example.com/api/index.php/v1/banners',curl -X GET 'https://example.com/api/index.php/v1/banners/{banner_id}',curl -X DELETE 'https://example.com/api/index.php/v1/banners/{banner_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/banners' -d {'catid': 3,'clicks': 0,'custombannercode': '','description': 'Text','metakey': '','name': 'Name','params': {'alt': '','height': '','imageurl': '','width': ''}},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/banners/{banner_id}' -d {'alias': 'name','catid': 3,'description': 'New Text','name': 'New Name'},curl -X GET 'https://example.com/api/index.php/v1/banners/clients',curl -X GET 'https://example.com/api/index.php/v1/banners/clients/{client_id}',curl -X DELETE 'https://example.com/api/index.php/v1/banners/clients/{client_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/banners/clients' -d {'contact': 'Name','email': 'email@mail.com','extrainfo': '','metakey': '','name': 'Clients','state': 1},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/banners/clients/{client_id}' -d {'contact': 'new Name','email': 'newemail@mail.com','name': 'Clients'},curl -X GET 'https://example.com/api/index.php/v1/banners/categories',curl -X GET 'https://example.com/api/index.php/v1/banners/categories/{category_id}',curl -X DELETE 'https://example.com/api/index.php/v1/banners/categories/{category_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/banners/categories' -d {'access': 1,'alias': 'cat','extension': 'com_banners','language': '*','note': '','parent_id': 1,'published': 1,'title': 'Title','params': {'workflow_id': 1}},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/banners/categories/{category_id}' -d {'alias': 'cat','note': 'Some Text','parent_id': 1,'title': 'New Title'},curl -X GET 'https://example.com/api/index.php/v1/banners/contenthistory/{banner_id}',curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/banners/contenthistory/keep/{contenthistory_id}',curl -X DELETE 'https://example.com/api/index.php/v1/banners/contenthistory/{contenthistory_id}',curl -X GET 'https://example.com/api/index.php/v1/config/application',curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/config/application' -d {'debug': true,'sitename': '123'},curl -X GET 'https://example.com/api/index.php/v1/config/{component_name}',curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/config/application' -d {'link_titles': 1},curl -X GET 'https://example.com/api/index.php/v1/contact',curl -X GET 'https://example.com/api/index.php/v1/contact/{contact_id}',curl -X DELETE 'https://example.com/api/index.php/v1/contact/{contact_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/contact' -d {'alias': 'contact','catid': 4,'language': '*','name': 'Contact'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/contact/{contact_id}' -d {'alias': 'contact','catid': 4,'name': 'New Contact'},curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/contact/form/{contact_id}' -d {'contact_email': 'email@mail.com','contact_message': 'some text','contact_name': 'name','contact_subject': 'subject'},curl -X GET 'https://example.com/api/index.php/v1/fields/contact/contact',curl -X GET 'https://example.com/api/index.php/v1/fields/contact/contact/{field_id}',curl -X DELETE 'https://example.com/api/index.php/v1/fields/contact/contact/{field_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/fields/contact/contact' -d {'access': 1,'context': 'com_contact.contact','default_value': '','description': '','group_id': 0,'label': 'contact field','language': '*','name': 'contact-field','note': '','params': {'class': '','display': '2','display_readonly': '2','hint': '','label_class': '','label_render_class': '','layout': '','prefix': '','render_class': '','show_on': '','showlabel': '1','suffix': ''},'required': 0,'state': 1,'title': 'contact field','type': 'text'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/fields/contact/contact/{field_id}' -d {'title': 'new contact field','name': 'contact-field','label': 'contact field','default_value': '','type': 'text','note': '','description': 'Some New Text'},curl -X GET 'https://example.com/api/index.php/v1/fields/groups/contact/contact',curl -X GET 'https://example.com/api/index.php/v1/fields/groups/contact/contact/{group_id}',curl -X DELETE 'https://example.com/api/index.php/v1/fields/groups/contact/contact/{group_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/fields/groups/contact/contact' -d {'access': 1,'context': 'com_contact.contact','default_value': '','description': '','group_id': 0,'label': 'contact field','language': '*','name': 'contact-field3','note': '','params': {'class': '','display': '2','display_readonly': '2','hint': '','label_class': '','label_render_class': '','layout': '','prefix': '','render_class': '','show_on': '','showlabel': '1','suffix': ''},'required': 0,'state': 1,'title': 'contact field','type': 'text'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/fields/groups/contact/contact/{group_id}' -d {'title': 'new contact group','note': '','description': 'new description'},curl -X GET 'https://example.com/api/index.php/v1/content/article',curl -X GET 'https://example.com/api/index.php/v1/content/article/{article_id}',curl -X DELETE 'https://example.com/api/index.php/v1/content/article/{article_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/content/article' -d {'alias': 'my-article','articletext': 'My text','catid': 64,'language': '*','metadesc': '','metakey': '','title': 'Here's an article'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/content/article/{article_id}' -d {'catid': 64,'title': 'Updated article'},curl -X GET 'https://example.com/api/index.php/v1/languages',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/languages' -d {'package': 'pkg_fr-FR'},curl -X GET 'https://example.com/api/index.php/v1/languages/content',curl -X GET 'https://example.com/api/index.php/v1/v1/languages/content/{language_id}',curl -X DELETE 'https://example.com/api/index.php/v1/languages/content/{language_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/languages/content' -d {'access': 1,'description': '','image': 'fr_FR','lang_code': 'fr-FR','metadesc': '','metakey': '','ordering': 1,'published': 0,'sef': 'fk','sitename': '','title': 'French (FR)','title_native': 'Français (France)'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/languages/content/{language_id}' -d {'description': '','lang_code': 'en-GB','metadesc': '','metakey': '','sitename': '','title': 'English (en-GB)','title_native': 'English (United Kingdom)'},curl -X GET 'https://example.com/api/index.php/v1/languages/overrides/{app}/{lang_code}',curl -X GET 'https://example.com/api/index.php/v1/languages/overrides/{app}/{lang_code}/{constant_id}',curl -X DELETE 'https://example.com/api/index.php/v1/languages/overrides/{app}/{lang_code}/{constant_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/languages/overrides/{app}/{lang_code}' -d {'key':'new_key','override': 'text'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/languages/overrides/{app}/{lang_code}/{constant_id}' -d {'key':'new_key','override': 'new text'},curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/languages/overrides/search' -d {'searchstring': 'JLIB_APPLICATION_ERROR_SAVE_FAILED','searchtype': 'constant'},curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/languages/overrides/search/cache/refresh',curl -X GET 'https://example.com/api/index.php/v1/menus/{app}',curl -X GET 'https://example.com/api/index.php/v1/menus/{app}/{menu_id}',curl -X DELETE 'https://example.com/api/index.php/v1/menus/{app}/{menu_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/menus/{app}' -d {'client_id': 0,'description': 'The menu for the site','menutype': 'menu','title': 'Menu'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/menus/{app}/{menu_id}' -d {'menutype': 'menu','title': 'New Menu'},curl -X GET 'https://example.com/api/index.php/v1/menus/{app}/items/types',curl -X GET 'https://example.com/api/index.php/v1/menus/{app}/items',curl -X GET 'https://example.com/api/index.php/v1/menus/{app}/items/{menu_item_id}',curl -X DELETE 'https://example.com/api/index.php/v1/menus/{app}/items/{menu_item_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/menus/{app}/items' -d {'access': '1','alias': '','associations': {'en-GB': '','fr-FR': ''},'browserNav': '0','component_id': '20','home': '0','language': '*','link': 'index.php?option=com_content&view=form&layout=edit','menutype': 'mainmenu','note': '','params': {'cancel_redirect_menuitem': '','catid': '','custom_cancel_redirect': '0','enable_category': '0','menu-anchor_css': '','menu-anchor_title': '','menu-meta_description': '','menu-meta_keywords': '','menu_image': '','menu_image_css': '','menu_show': '1','menu_text': '1','page_heading': '','page_title': '','pageclass_sfx': '','redirect_menuitem': '','robots': '','show_page_heading': ''},'parent_id': '1','publish_down': '','publish_up': '','published': '1','template_style_id': '0','title': 'title','toggle_modules_assigned': '1','toggle_modules_published': '1','type': 'component'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/menus/{app}/items/{menu_item_id}' -d {'component_id': '20','language': '*','link': 'index.php?option=com_content&view=form&layout=edit','menutype': 'mainmenu','note': '','title': 'new title','type': 'component'},curl -X GET 'https://example.com/api/index.php/v1/messages',curl -X GET 'https://example.com/api/index.php/v1/messages/{message_id}',curl -X DELETE 'https://example.com/api/index.php/v1/messages/{message_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/messages' -d {'message': '<p>text</p>','state': 0,'subject': 'text','user_id_from': 773,'user_id_to': 772},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/messages/{message_id}' -d {'message': '<p>new text</p>','subject': 'new text','user_id_from': 773,'user_id_to': 772},curl -X GET 'https://example.com/api/index.php/v1/modules/types/{app}',curl -X GET 'https://example.com/api/index.php/v1/modules/{app}',curl -X GET 'https://example.com/api/index.php/v1/modules/{app}/{module_id}',curl -X DELETE 'https://example.com/api/index.php/v1/modules/{app}/{module_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/modules/{app}' -d {'access': '1','assigned': ['101','105'],'assignment': '0','client_id': '0','language': '*','module': 'mod_articles_archive','note': '','ordering': '1','params': {'bootstrap_size': '0','cache': '1','cache_time': '900','cachemode': 'static','count': '10','header_class': '','header_tag': 'h3','layout': '_:default','module_tag': 'div','moduleclass_sfx': '','style': '0'},'position': '','publish_down': '','publish_up': '','published': '1','showtitle': '1','title': 'Title'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/modules/{app}/{module_id}' -d {'access': '1','client_id': '0','language': '*','module': 'mod_articles_archive','note': '','ordering': '1','title': 'New Title'},curl -X GET 'https://example.com/api/index.php/v1/newsfeeds/feeds',curl -X GET 'https://example.com/api/index.php/v1/newsfeeds/feeds/{feed_id}',curl -X DELETE 'https://example.com/api/index.php/v1/newsfeeds/feeds/{feed_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/newsfeeds/feeds' -d {'access': 1,'alias': 'alias','catid': 5,'description': '','images': {'float_first': '','float_second': '','image_first': '','image_first_alt': '','image_first_caption': '','image_second': '','image_second_alt': '','image_second_caption': ''},'language': '*','link': 'http://samoylov/joomla/gsoc19_webservices/index.php','metadata': {'hits': '','rights': '','robots': '','tags': {'tags': '','typeAlias': null}},'metadesc': '','metakey': '','name': 'Name','ordering': 1,'params': {'feed_character_count': '','feed_display_order': '','newsfeed_layout': '','show_feed_description': '','show_feed_image': '','show_item_description': ''},'published': 1},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/newsfeeds/feeds/{feed_id}' -d {'access': 1,'alias': 'test2','catid': 5,'description': '','link': 'http://samoylov/joomla/gsoc19_webservices/index.php','metadesc': '','metakey': '','name': 'Test'},curl -X GET 'https://example.com/api/index.php/v1/privacy/request',curl -X GET 'https://example.com/api/index.php/v1/privacy/request/{request_id}',curl -X GET 'https://example.com/api/index.php/v1/privacy/request/export/{request_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/privacy/request' -d {'email':'somenewemail@com.ua','request_type':'export'},curl -X GET 'https://example.com/api/index.php/v1/privacy/consent',curl -X GET 'https://example.com/api/index.php/v1/privacy/consent/{consent_id}',curl -X DELETE 'https://example.com/api/index.php/v1/privacy/consent/{consent_id}',curl -X GET 'https://example.com/api/index.php/v1/redirect',curl -X GET 'https://example.com/api/index.php/v1/redirect/{redirect_id}',curl -X DELETE 'https://example.com/api/index.php/v1/redirect/{redirect_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/redirect' -d {'comment': '','header': 301,'hits': 0,'new_url': '/content/art/99','old_url': '/content/art/12','published': 1,'referer': ''},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/redirect/{redirect_id}' -d {'new_url': '/content/art/4','old_url': '/content/art/132'},curl -X GET 'https://example.com/api/index.php/v1/tags',curl -X GET 'https://example.com/api/index.php/v1/tags/{tag_id}',curl -X DELETE 'https://example.com/api/index.php/v1/tags/{tag_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/tags' -d {'access': 1,'access_title': 'Public','alias': 'test','description': '','language': '*','note': '','parent_id': 1,'path': 'test','published': 1,'title': 'test'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/tags/{tag_id}' -d{'alias': 'test','title': 'new title'},curl -X GET 'https://example.com/api/index.php/v1/templates/styles/{app}',curl -X GET 'https://example.com/api/index.php/v1/templates/styles/{app}/{template_style_id}',curl -X DELETE 'https://example.com/api/index.php/v1/templates/styles/{app}/{template_style_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/templates/styles/{app}' -d {'home': '0','params': {'fluidContainer': '0','logoFile': '','sidebarLeftWidth': '3','sidebarRightWidth': '3'},'template': 'cassiopeia','title': 'cassiopeia - Some Text'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/templates/styles/{app}/{template_style_id}' -d {'template': 'cassiopeia','title': 'new cassiopeia - Default'},curl -X GET 'https://example.com/api/index.php/v1/users',curl -X GET 'https://example.com/api/index.php/v1/users/{user_id}',curl -X DELETE 'https://example.com/api/index.php/v1/users/{user_id}',curl -X POST -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/users' -d {'block': '0','email': 'test@mail.com','groups': ['2'],'id': '0','lastResetTime': '','lastvisitDate': '','name': 'nnn','params': {'admin_language': '','admin_style': '','editor': '','helpsite': '','language': '','timezone': ''},'password': 'qwerty','password2': 'qwerty','registerDate': '','requireReset': '0','resetCount': '0','sendEmail': '0','username': 'ad'},curl -X PATCH -H 'Content-Type: application/json' 'https://example.com/api/index.php/v1/users/{user_id}' -d {'email': 'new@mail.com','groups': ['2'],'name': 'name','username': 'username'}],
collection = new Collection();

Promise.all(curlRequests.map((currentRequest) => {
return new Promise((resolve, reject) => {
curlToPostman.convert({type: ‘string’, data: currentRequest}, (err, result) => {
if (err) {
return reject(err);
}
if (!result || !result.output || !result.output.length) {
return reject(result);
}
collection.items.add({
name: result.output[0] && result.output[0].data.name,
request: result.output[0] && result.output[0].data
});

return resolve();
});
});
}))
.then(() => {
console.log(JSON.stringify(collection.toJSON()));
})
.catch((err) => {
console.log(err);
});

Please tell me what I am doing wrong

@alexandree,
I see a few issues in the snippet you shared.

  1. Every item in the array should be a string. It’s not so in the snippet you shared. Please enclose every request in " or use template literals (``). I’d recommend using template literals.
  2. Your cURL seems to be invalid too. Can you enclose the JSON that follows -d in " too?

I made these changes locally and the script I shared is returning the right result. It should work for you too.

Hello,
The requests locally have the template backtick. Maybe it has been removed when I posted the code. But indeed. I done wrong with the -d data. I’ll try again locally. Thanks again. If it works for you locally it should work for me too.

Take care @bhargavkaranam96