Every time we create or update an API in the backend (Node.js), we have to manually go to Postman, add the route, method, request body, expected response, and organize it into folders. It's repetitive, error-prone, and a waste of time—especially when we're iterating fast in development.
Imagine this:
- You tell your AI agent to create/update an Express route
- It auto-generates the updated Postman collection JSON
- And with a single command, your Postman app is updated instantly.
Tell your agent (e.g., inside VS Code + Cursor or a CLI tool) to:
Read all Express route files in this project and generate a Postman collection JSON containing:
- All routes and methods
- Example request and response bodies
- Use variable for base URL (e.g., {{base_url}})
- Group endpoints by filename (as folders in Postman)
This generates a postman_collection.json
file in your project root.
In your project root, create a file syncPostmanCollection.js
:
"use strict";
const fs = require("fs");
const axios = require("axios");
// Configuration
const POSTMAN_API_KEY = "PMAK-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Replace with your API Key
const WORKSPACE_ID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // Replace with your workspace ID
const COLLECTION_UID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // Optional: If updating existing collection
// Read collection from file
const collection = JSON.parse(
fs.readFileSync("postman_collection.json", "utf8")
);
// API request headers
const headers = {
"X-Api-Key": POSTMAN_API_KEY,
"Content-Type": "application/json"
};
/**
* Uploads or updates the Postman collection
*/
async function uploadCollection() {
try {
if (COLLECTION_UID) {
// Update existing collection
await axios.put(
`https://api.getpostman.com/collections/${COLLECTION_UID}`,
{ collection },
{ headers }
);
console.log("✅ Collection updated in Postman");
} else {
// Create new collection
await axios.post(
"https://api.getpostman.com/collections",
{ collection, workspace: WORKSPACE_ID },
{ headers }
);
console.log("✅ Collection created in Postman");
}
} catch (err) {
console.error("❌ Failed to sync with Postman:", err.response?.data || err);
}
}
// Execute the upload
uploadCollection();
Add this script to your package.json:
{
"scripts": {
"sync:postman": "node syncPostmanCollection.js"
}
}
Now you can run:
npm run sync:postman
Whenever you add or update a route, just tell your agent:
In router `user.js`, add `createUser` POST API.
Then, update the `postman_collection.json` and run `npm run sync:postman`
The agent:
- Updates your Express code
- Modifies the postman_collection.json
- Syncs Postman in one shot 🎯
Traditional Workflow | Agentic Sync Workflow |
---|---|
Manual Postman updates after every route change | Just speak/update code, Postman syncs automatically |
Repetitive and error-prone | Fully automated and always up-to-date |
Wasted 10–15 mins per update | Saved hours every day |
Tedious folder creation in Postman | Auto-grouped by filename |
If you're working in an AI-augmented coding environment, this Postman sync system is a game-changer. It keeps your API docs updated automatically, and removes a major pain point from backend workflows.
This can be used in all backend projects, and it's fantastic. Set it up once, and forget about manual Postman updates forever.
Set this up in your project today and let your agent handle the rest!