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.

Revisions

  1. DannyDainton revised this gist Mar 5, 2026. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion copy_collection.sh
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@

    set -euo pipefail

    API_KEY="POST API KEY"
    API_KEY="POSTMAN_API_KEY"
    BASE_URL="https://api.getpostman.com"

    COLLECTION_ID="${1:?Usage: $0 <collection_id> <workspace_id>}"
  2. DannyDainton revised this gist Mar 5, 2026. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions copy_collection.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    #!/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
  3. DannyDainton created this gist Mar 5, 2026.
    47 changes: 47 additions & 0 deletions copy_collection.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/bin/bash

    # Copy a Postman Collection to a different workspace
    # Usage: ./copy_collection.sh <collection_id> <workspace_id>

    set -euo pipefail

    API_KEY="POST 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"