Skip to content

Commit d43eaec

Browse files
committed
scripts created and README updated
1 parent aa9b858 commit d43eaec

4 files changed

Lines changed: 217 additions & 17 deletions

File tree

README.md

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# Postman Content Exporter
22

3-
This repository has been reorganized. All scripts are now in the [export-content directory](./export-content) for better organization.
3+
This repository contains tools for exporting Postman collections, environments, and workspace information via the Postman API.
4+
5+
## Features
6+
7+
- Export Postman collections and environments
8+
- Generate workspace admin reports
9+
- Interactive shell scripts for easy usage
410

511
## Prerequisites
612

713
- Node.js (v14 or later recommended)
8-
- A Postman API key with read access to your collections and environments
14+
- A Postman API key with read access to your collections, environments, and workspaces
915

1016
## Setup
1117

12-
Please see the detailed setup instructions in the [export-content README](./export-content/README.md).
13-
14-
## Quick Start
15-
1618
1. Install dependencies:
1719
```
1820
npm install
@@ -23,9 +25,27 @@ Please see the detailed setup instructions in the [export-content README](./expo
2325
export POSTMAN_API_KEY="your-api-key-here"
2426
```
2527

26-
3. Run the interactive shell script:
27-
```
28-
./export-content/run-export.sh
29-
```
28+
## Quick Start
29+
30+
### Exporting Collections and Environments
31+
32+
Run the interactive shell script:
33+
```
34+
./export-content/run-export.sh
35+
```
3036

3137
For more detailed information, please check the [export-content README](./export-content/README.md).
38+
39+
### Generating Workspace Admin Reports
40+
41+
Run the interactive shell script:
42+
```
43+
./get-workspace-admins/run-admin-report.sh
44+
```
45+
46+
Or use npm:
47+
```
48+
npm run admin-report
49+
```
50+
51+
For more detailed information, please check the [get-workspace-admins README](./get-workspace-admins/README.md).

get-workspace-admins/README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,48 @@ This directory contains scripts to retrieve information about Postman workspaces
55
## Scripts
66

77
- `get-team-workspaces.js`: Retrieves all Postman workspaces with visibility set to 'team' and generates an HTML report of workspace admins
8+
- `run-admin-report.sh`: Interactive shell script to run the workspace admins report with user-friendly prompts
9+
- `report-template.hbs`: Handlebars template for generating the HTML report
810

911
## Usage
1012

1113
### Prerequisites
1214

1315
- Node.js (v14 or later recommended)
1416
- A Postman API key with read access to your workspaces
15-
- Handlebars (will be installed when you run `npm install`)
17+
- Handlebars (will be installed automatically by the shell script if needed)
1618

1719
### Setup
1820

1921
1. Ensure you're in the project root directory
2022
2. Install dependencies if you haven't already:
2123
```
22-
npm install handlebars
24+
npm install
2325
```
2426

25-
3. Set your Postman API key as an environment variable:
27+
3. Make the shell script executable:
2628
```
27-
export POSTMAN_API_KEY="your-api-key-here"
29+
chmod +x get-workspace-admins/run-admin-report.sh
2830
```
2931

30-
### Retrieving Team Workspaces and Admins
32+
### Running the Interactive Shell Script (Recommended)
3133

32-
Run the script to fetch all workspaces with 'team' visibility and their admin users:
34+
The easiest way to generate the workspace admins report is to use the interactive shell script:
35+
36+
```
37+
./get-workspace-admins/run-admin-report.sh
38+
```
39+
40+
This script will:
41+
1. Check if you have Node.js installed
42+
2. Prompt you to set your Postman API key if not already set
43+
3. Allow you to specify a custom output directory
44+
4. Run the report generation script
45+
5. Offer to open the HTML report in your default browser
46+
47+
### Running the Node.js Script Directly
48+
49+
Alternatively, you can run the Node.js script directly:
3350

3451
```
3552
node get-workspace-admins/get-team-workspaces.js [output-directory]
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#!/bin/bash
2+
3+
# Colors for better readability
4+
GREEN='\033[0;32m'
5+
BLUE='\033[0;34m'
6+
YELLOW='\033[1;33m'
7+
NC='\033[0m' # No Color
8+
9+
# Default output directory
10+
DEFAULT_OUTPUT_DIR="../postman-export/workspaces"
11+
12+
# Get the directory where the script is located
13+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
14+
# Get the parent directory (project root)
15+
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
16+
17+
# Display a welcome message
18+
echo -e "${GREEN}=================================${NC}"
19+
echo -e "${GREEN}Postman Workspace Admins Report${NC}"
20+
echo -e "${GREEN}=================================${NC}"
21+
22+
# Function to check if the API key is set
23+
check_api_key() {
24+
if [ -z "$POSTMAN_API_KEY" ]; then
25+
echo -e "${YELLOW}Warning: POSTMAN_API_KEY environment variable is not set.${NC}"
26+
echo -e "Would you like to set it now? (y/n)"
27+
read -r set_api_key
28+
29+
if [[ "$set_api_key" == "y" || "$set_api_key" == "Y" ]]; then
30+
echo -e "Enter your Postman API key:"
31+
read -r api_key
32+
export POSTMAN_API_KEY="$api_key"
33+
echo -e "${GREEN}API key set for this session.${NC}"
34+
35+
echo -e "Would you like to save this API key to your shell profile? (y/n)"
36+
read -r save_api_key
37+
38+
if [[ "$save_api_key" == "y" || "$save_api_key" == "Y" ]]; then
39+
if [[ "$SHELL" == *"zsh"* ]]; then
40+
PROFILE_FILE="$HOME/.zshrc"
41+
elif [[ "$SHELL" == *"bash"* ]]; then
42+
if [[ "$OSTYPE" == "darwin"* ]]; then
43+
PROFILE_FILE="$HOME/.bash_profile"
44+
else
45+
PROFILE_FILE="$HOME/.bashrc"
46+
fi
47+
else
48+
echo -e "${YELLOW}Could not determine your shell profile. API key will not be saved.${NC}"
49+
return
50+
fi
51+
52+
echo "" >> "$PROFILE_FILE"
53+
echo "# Postman API Key" >> "$PROFILE_FILE"
54+
echo "export POSTMAN_API_KEY=\"$api_key\"" >> "$PROFILE_FILE"
55+
echo -e "${GREEN}API key saved to $PROFILE_FILE${NC}"
56+
fi
57+
else
58+
echo -e "${YELLOW}You'll need to set the POSTMAN_API_KEY environment variable to use this script.${NC}"
59+
exit 1
60+
fi
61+
fi
62+
}
63+
64+
# Function to get output directory
65+
get_output_dir() {
66+
echo ""
67+
echo -e "${BLUE}Would you like to use a custom output directory? (y/n) ${NC}"
68+
echo -e "Default: ${DEFAULT_OUTPUT_DIR}"
69+
read -r use_custom_dir
70+
71+
if [[ "$use_custom_dir" == "y" || "$use_custom_dir" == "Y" ]]; then
72+
echo -n "Enter output directory path: "
73+
read -r output_dir
74+
75+
# Check if the path is absolute or relative
76+
if [[ "$output_dir" != /* ]]; then
77+
# Convert to absolute path
78+
output_dir="$PROJECT_ROOT/$output_dir"
79+
fi
80+
81+
echo -e "Using output directory: ${YELLOW}$output_dir${NC}"
82+
else
83+
output_dir="$PROJECT_ROOT/postman-export/workspaces"
84+
echo -e "Using default output directory: ${YELLOW}$output_dir${NC}"
85+
fi
86+
}
87+
88+
# Check for dependencies
89+
check_dependencies() {
90+
if ! command -v node &> /dev/null; then
91+
echo -e "${YELLOW}Node.js is not installed. Please install Node.js before continuing.${NC}"
92+
exit 1
93+
fi
94+
95+
# Switch to project root to check for package.json
96+
cd "$PROJECT_ROOT"
97+
98+
if [ ! -f package.json ]; then
99+
echo -e "${YELLOW}Warning: package.json not found. Are you in the correct directory?${NC}"
100+
fi
101+
102+
# Check if dependencies are installed
103+
if [ ! -d "node_modules" ]; then
104+
echo -e "${YELLOW}Node modules not found. Installing dependencies...${NC}"
105+
npm install
106+
fi
107+
108+
# Check specifically for Handlebars
109+
if ! grep -q "handlebars" package.json; then
110+
echo -e "${YELLOW}Handlebars dependency not found in package.json. Installing...${NC}"
111+
npm install handlebars
112+
fi
113+
}
114+
115+
# Function to open the HTML report in the default browser
116+
open_report() {
117+
echo ""
118+
echo -e "${BLUE}Would you like to open the HTML report in your browser? (y/n) ${NC}"
119+
read -r open_browser
120+
121+
if [[ "$open_browser" == "y" || "$open_browser" == "Y" ]]; then
122+
report_path="$output_dir/admin-report.html"
123+
124+
if [[ "$OSTYPE" == "darwin"* ]]; then
125+
# macOS
126+
open "$report_path"
127+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
128+
# Linux
129+
xdg-open "$report_path"
130+
elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
131+
# Windows
132+
start "$report_path"
133+
else
134+
echo -e "${YELLOW}Couldn't determine how to open the report on your system.${NC}"
135+
echo -e "Report is located at: ${report_path}"
136+
fi
137+
fi
138+
}
139+
140+
# Main script execution
141+
echo -e "${BLUE}This script will generate a report of all team workspaces and their admin users.${NC}"
142+
check_dependencies
143+
check_api_key
144+
get_output_dir
145+
146+
# Run the workspace admin report
147+
echo -e "${GREEN}Fetching workspace data and generating report...${NC}"
148+
cd "$PROJECT_ROOT" && node get-workspace-admins/get-team-workspaces.js "$output_dir"
149+
150+
# Check if the report was generated successfully
151+
if [ $? -eq 0 ]; then
152+
echo -e "${GREEN}Report generated successfully!${NC}"
153+
echo -e "JSON data saved to: ${YELLOW}$output_dir/workspace-admins-report.json${NC}"
154+
echo -e "HTML report saved to: ${YELLOW}$output_dir/admin-report.html${NC}"
155+
156+
# Ask if the user wants to open the report
157+
open_report
158+
else
159+
echo -e "${YELLOW}Error generating the report. Please check the console output for details.${NC}"
160+
fi
161+
162+
exit 0

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"get-environments:custom": "node export-content/get-environments.js",
1919
"export-all:custom": "node export-content/export-all.js",
2020
"export-consolidated:custom": "node export-content/export-consolidated.js",
21-
"get-team-workspaces": "node get-workspace-admins/get-team-workspaces.js"
21+
"get-team-workspaces": "node get-workspace-admins/get-team-workspaces.js",
22+
"admin-report": "bash get-workspace-admins/run-admin-report.sh"
2223
},
2324
"dependencies": {
2425
"axios": "^1.12.2",

0 commit comments

Comments
 (0)