Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions .github/workflows/sync-postman-collection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: Sync Postman Collection

on:
push:
branches:
- main
paths:
- 'StackOne_postman_collection.json'

jobs:
sync-postman:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install Newman (Postman CLI)
run: npm install -g newman

Comment on lines +23 to +25
Copy link

Copilot AI Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newman is installed but never used in the workflow. The sync operations use curl with the Postman API directly. Consider removing this step or use Newman for the API operations if preferred.

Suggested change
- name: Install Newman (Postman CLI)
run: npm install -g newman

Copilot uses AI. Check for mistakes.
- name: Check if collection exists in Postman
id: check_collection
env:
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
POSTMAN_WORKSPACE_ID: ${{ secrets.POSTMAN_WORKSPACE_ID }}
run: |
# Get all collections in workspace
response=$(curl -s -X GET \
"https://api.getpostman.com/collections?workspace=$POSTMAN_WORKSPACE_ID" \
-H "X-Api-Key: $POSTMAN_API_KEY")
# Check if StackOne collection exists
collection_uid=$(echo "$response" | jq -r '.collections[] | select(.name == "StackOne") | .uid' | head -1)
Copy link

Copilot AI Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script assumes jq is available but doesn't install it. Ubuntu runners don't have jq pre-installed by default. Add a step to install jq or use the jq action.

Copilot uses AI. Check for mistakes.
if [ -n "$collection_uid" ]; then
echo "Collection exists with UID: $collection_uid"
echo "collection_exists=true" >> $GITHUB_OUTPUT
echo "collection_uid=$collection_uid" >> $GITHUB_OUTPUT
else
echo "Collection does not exist"
echo "collection_exists=false" >> $GITHUB_OUTPUT
fi
- name: Update existing collection
if: steps.check_collection.outputs.collection_exists == 'true'
env:
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
COLLECTION_UID: ${{ steps.check_collection.outputs.collection_uid }}
run: |
# Read the collection file
collection_json=$(cat StackOne_postman_collection.json)
# Update the existing collection
response=$(curl -s -w "\n%{http_code}" -X PUT \
"https://api.getpostman.com/collections/$COLLECTION_UID" \
-H "X-Api-Key: $POSTMAN_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"collection\": $collection_json}")
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -eq 200 ]; then
echo "✅ Successfully updated collection"
echo "$body" | jq '.'
else
echo "❌ Failed to update collection. HTTP Code: $http_code"
echo "Response: $body"
exit 1
fi
- name: Create new collection
if: steps.check_collection.outputs.collection_exists == 'false'
env:
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
POSTMAN_WORKSPACE_ID: ${{ secrets.POSTMAN_WORKSPACE_ID }}
run: |
# Read the collection file
collection_json=$(cat StackOne_postman_collection.json)
# Create new collection
response=$(curl -s -w "\n%{http_code}" -X POST \
"https://api.getpostman.com/collections?workspace=$POSTMAN_WORKSPACE_ID" \
-H "X-Api-Key: $POSTMAN_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"collection\": $collection_json}")
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -eq 200 ]; then
Copy link

Copilot AI Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Postman API returns HTTP 201 (Created) for successful POST requests to create collections, not 200. This condition should check for 201 instead of 200.

Suggested change
if [ "$http_code" -eq 200 ]; then
if [ "$http_code" -eq 201 ]; then

Copilot uses AI. Check for mistakes.
echo "✅ Successfully created new collection"
echo "$body" | jq '.'
else
echo "❌ Failed to create collection. HTTP Code: $http_code"
echo "Response: $body"
exit 1
fi
- name: Verify sync
env:
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
POSTMAN_WORKSPACE_ID: ${{ secrets.POSTMAN_WORKSPACE_ID }}
run: |
echo "🔍 Verifying collection sync..."
# Get collections again to verify
response=$(curl -s -X GET \
"https://api.getpostman.com/collections?workspace=$POSTMAN_WORKSPACE_ID" \
-H "X-Api-Key: $POSTMAN_API_KEY")
stackone_collection=$(echo "$response" | jq '.collections[] | select(.name == "StackOne")')
if [ -n "$stackone_collection" ]; then
echo "✅ Collection verified in workspace"
echo "$stackone_collection" | jq '.'
else
echo "❌ Collection not found after sync"
exit 1
fi
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ To use the Postman collection, follow these steps:
- **Collection Name:** StackOne
- **Schema Version:** [Postman Collection Schema v2.1.0](https://schema.getpostman.com/json/collection/v2.1.0/collection.json)

## Automated Sync to Postman

This repository includes a GitHub workflow that automatically syncs the Postman collection to your Postman workspace when changes are merged to the main branch.

### Setup Requirements

To enable automatic synchronization, you need to configure the following GitHub secrets in your repository:

1. **`POSTMAN_API_KEY`**: Your Postman API key
- Generate from: [Postman Account Settings](https://postman.co/settings/me/api-keys)
Copy link

@cubic-dev-ai cubic-dev-ai bot Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect Postman settings URL (postman.co). Use the official postman.com web app URL so users can generate an API key successfully.

Prompt for AI agents
Address the following comment on README.md at line 34:

<comment>Incorrect Postman settings URL (postman.co). Use the official postman.com web app URL so users can generate an API key successfully.</comment>

<file context>
@@ -22,6 +22,29 @@ To use the Postman collection, follow these steps:
+To enable automatic synchronization, you need to configure the following GitHub secrets in your repository:
+
+1. **`POSTMAN_API_KEY`**: Your Postman API key
+   - Generate from: [Postman Account Settings](https://postman.co/settings/me/api-keys)
+   - Required permissions: Collection management
+
</file context>
Suggested change
- Generate from: [Postman Account Settings](https://postman.co/settings/me/api-keys)
- Generate from: [Postman Account Settings](https://web.postman.com/settings/me/api-keys)
Fix with Cubic

- Required permissions: Collection management

2. **`POSTMAN_WORKSPACE_ID`**: Your Postman workspace ID
- Find in Postman: Go to your workspace → Settings → Info → Workspace ID
- Or via API: `GET https://api.getpostman.com/workspaces`

### How It Works

- The workflow triggers when changes to `StackOne_postman_collection.json` are pushed to the main branch (including PR merges)
- If a collection named "StackOne" exists in your workspace, it will be updated
- If no collection exists, a new one will be created
- The workflow uses the official Postman API for all operations

## Contributing

If you find any issues or have suggestions for improvements, please submit an issue or pull request on this repository.
Expand Down