Skip to content

Latest commit

 

History

History
121 lines (88 loc) · 4.28 KB

File metadata and controls

121 lines (88 loc) · 4.28 KB

Postman Content Exporter

This tool allows you to retrieve all your Postman collections and environments using the Postman API.

Prerequisites

  • Node.js (v14 or later recommended)
  • A Postman API key with read access to your collections and environments

Setup

  1. Install dependencies:

    npm install
    
  2. OPTIONAL: Set your Postman API key as an environment variable:

    export POSTMAN_API_KEY="your-api-key-here"
    

    If no POSTMAN_API_KEY environment variable is defined, the export script will give you an opportunity to enter it.

Usage

Interactive Shell Script

The easiest way to use this tool is with the interactive shell script:

./export-content/run-export.sh

This script will:

  1. Check if you have Node.js installed
  2. Prompt you to set your Postman API key if not already set
  3. Let you choose which export operation to perform
  4. Allow you to specify a custom output directory
  5. Run the appropriate export script

Using Node directly

You can also just run with Node, specifying a custom output directory:

node export-content/get-collections.js [output-directory] [--consolidated]
node export-content/get-environments.js [output-directory]
node export-content/export-all.js [output-directory] [--consolidated]
node export-content/export-consolidated.js [output-directory]

Options:

  • --consolidated: Export collections as a single consolidated file instead of individual files
    • For get-collections.js: Saves all collections to a single JSON file named all-collections.json
    • For export-all.js: Saves all collections to a single file while still exporting environments as individual files

Example with custom output directory:

node export-content/get-collections.js ./my-custom-path
node export-content/get-collections.js ./my-custom-path --consolidated
node export-content/export-all.js ./my-custom-path --consolidated
node export-content/export-consolidated.js ./exports/postman

Default Output Directories

If no output directory is specified, the scripts will use these defaults:

  • export-content/get-collections.js: ./postman-export/collections
  • export-content/get-environments.js: ./postman-export/environments
  • export-all.js: ./postman-export (with subdirectories for collections and environments)
  • export-consolidated.js: ./postman-export (with the consolidated file)

When specifying a custom output directory:

  • get-collections.js will create a collections subdirectory in your specified path
  • get-environments.js will create an environments subdirectory in your specified path
  • export-all.js will create both subdirectories in your specified path
  • export-consolidated.js will create a single JSON file in your specified path

Output

The scripts will create the following directories and files:

Default Directory Structure

  • postman-export/collections/: Contains all your Postman collections

    • collections-metadata.json: A summary of all your collections
    • Individual JSON files for each collection, named after the collection (in default mode)
    • consolidated-collections.json: A single file containing all collections (when using --consolidated flag)
  • postman-export/environments/: Contains all your Postman environments

    • environments-metadata.json: A summary of all your environments
    • Individual JSON files for each environment, named after the environment
  • postman-export/: Contains consolidated export files

    • postman-export.json: A single JSON file containing all collections and environments in the structure:
      {
        "collections": [
          // Collection objects
        ],
        "environments": [
          // Environment objects
        ]
      }

If you specify a custom output directory, the files will be created in that location instead.

How to Get Your Postman API Key

  1. Log in to your Postman account
  2. Go to your API Keys page
  3. Create a new API key with appropriate scopes (at minimum, you need read access to collections and environments)
  4. Copy the generated key and use it in this script

Troubleshooting

  • If you encounter permission issues, make sure your API key has the correct scopes
  • If you get rate limit errors, the script may need to be modified to include pagination or delays