Skip to content

Instantly share code, notes, and snippets.

@DannyDainton
Last active March 5, 2026 21:24
Show Gist options
  • Select an option

  • Save DannyDainton/be112eb94dfd57186e203273bc9d52b6 to your computer and use it in GitHub Desktop.

Select an option

Save DannyDainton/be112eb94dfd57186e203273bc9d52b6 to your computer and use it in GitHub Desktop.
This script can be using to move a Postman Collection from a Shared Workspace to an Internal Workspace.
#!/bin/bash
# Copy a Postman Collection to a different workspace
# Create a new Postman API Key for your user https://go.postman.co/settings/me/api-keys and add this to the API_KEY variable
# Usage: ./copy_collection.sh <collection_id> <workspace_id>
set -euo pipefail
API_KEY="POSTMAN_API_KEY"
BASE_URL="https://api.getpostman.com"
COLLECTION_ID="${1:?Usage: $0 <collection_id> <workspace_id>}"
WORKSPACE_ID="${2:?Usage: $0 <collection_id> <workspace_id>}"
echo "Fetching collection ${COLLECTION_ID}..."
RESPONSE=$(curl -s -w "\n%{http_code}" \
-X GET "${BASE_URL}/collections/${COLLECTION_ID}" \
-H "X-Api-Key: ${API_KEY}")
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
BODY=$(echo "$RESPONSE" | sed '$d')
if [[ "$HTTP_CODE" -ne 200 ]]; then
echo "Error: GET /collections/${COLLECTION_ID} returned HTTP ${HTTP_CODE}"
echo "$BODY"
exit 1
fi
echo "Creating collection in workspace ${WORKSPACE_ID}..."
POST_RESPONSE=$(curl -s -w "\n%{http_code}" \
-X POST "${BASE_URL}/collections?workspace=${WORKSPACE_ID}" \
-H "X-Api-Key: ${API_KEY}" \
-H "Content-Type: application/json" \
-d "$BODY")
POST_HTTP_CODE=$(echo "$POST_RESPONSE" | tail -n1)
POST_BODY=$(echo "$POST_RESPONSE" | sed '$d')
if [[ "$POST_HTTP_CODE" -ne 200 ]]; then
echo "Error: POST /collections returned HTTP ${POST_HTTP_CODE}"
echo "$POST_BODY"
exit 1
fi
echo "Collection copied successfully!"
echo "$POST_BODY"

Comments are disabled for this gist.