postman

How to convert Postman backup file into Collection files


I was using Postman without an account, with all my collections saved locally. Today, my Postman was updated to stop allowing this, leaving only a "lightweight" client that cannot use collections.

I can only export a JSON dump "backup" file, but not an actual Collection V2 file, which I need to import to the tool that I will use in replacement of Postman.

How can I (with a tool or manually) convert the JSON dump into Collection files?

Do note: creating a Postman account is NOT an option. I'm looking for a solution that does not require me to create an account.


Solution

  • I had the same problem:

    it seems the backup dump file contains the collections in postman version 1, in field "collections":
    if you only need the collections (i.e. not global environments etc) you can store each entry in "collections" to a separate file which would result in v1 formatted collections.

    If you need v2 collections, you could convert them, e.g. with the npm package postman-collection-transformer (for Node.js)

    As an example, here is a simple conversion script based on postman-collection-transformer's README

    replace <postman_backup_dump.json> and <output-directory> with appropriate strings; if the collections have names that cannot be used as file-names, you would need to do some additional changes when creating the output file name

    var transformer = require('postman-collection-transformer'),
        fs = require('fs'),
        path = require('path');
    
    
    var collection = require('<postman_backup_dump.json>');
    var options = {
        inputVersion: '1.0.0',
        outputVersion: '2.0.0',
        retainIds: true  // the transformer strips request-ids etc by default.
    };
    
    var outDir = '<output-directory>';
    
    
    collection.collections.forEach(function(coll){
    
        transformer.convert(coll, options, function (error, result) {
            if (error) {
                return console.error(error);
            }
    
            var content = JSON.stringify(result, null, 2);
            var index = 0;
            var name = result.info.name + '.json';
            while(fs.existsSync(path.resolve(outDir, name))){
                name = result.info.name + '_' + (++index) + '.json';
            }
            fs.writeFileSync(path.resolve(outDir, name), content, 'utf-8');
        });
    });