# Automate API Collections, Environments, and Tests with Agent Mode

Source: https://www.youtube.com/watch?v=h2eoW99bRFk
Recap page: https://rapidrecap.app/video/h2eoW99bRFk
Generated: 2025-11-10T23:11:36.654+00:00

---
## Quick Overview

The video demonstrates how to automate API collection creation, environment setup, and test generation in Postman using Agent Mode by connecting it to a local file system containing a Flask application's code, resulting in a fully functional collection with comprehensive tests that pass after minor AI-suggested fixes.

**Key Points:**
- The user connects a Postman workspace to a local file system containing a Python Flask e-commerce application's code.
- Agent Mode automatically generates an API collection named "ecommerce FS APIs" based on the structure of the local files (e.g., app.py).
- Agent Mode also imports three distinct environments (dev, prod, staging) found in the local project structure.
- The AI generates comprehensive tests for every request in the collection, including status code checks, header validations, and schema validation.
- After running the initial collection tests, three tests failed, which Agent Mode identified and provided specific recommendations to fix.
- Upon implementing the AI's fixes, all 68 tests passed, successfully demonstrating end-to-end automation for collection setup and testing.
- The process showcased variable management by automatically setting up environment variables like base URLs for dev, staging, and prod.

![Screenshot at 0:05: The user navigates the Postman interface to initiate the creation of a new workspace linked directly to a local repository folder containing the application source code.](https://ss.rapidrecap.app/screens/h2eoW99bRFk/00-00-05.png)

**Context:** The video showcases a demonstration of Postman's Agent Mode functionality, which utilizes AI capabilities to bridge the gap between local source code and the Postman API development platform. The presenter uses a pre-existing local Python Flask application for a basic e-commerce backend to illustrate how Agent Mode can automatically generate a Postman Collection, create necessary environments for different stages (dev, prod, staging), and write comprehensive pre-request and post-response tests for the API endpoints defined in the code.

## Detailed Analysis

The demonstration begins by connecting Postman to a local file system containing a Python Flask e-commerce application located in an 'ecommerce' folder. The presenter clicks 'Workspaces' and selects the option to 'Create Workspace From Local Repository Folder' (0:05). After selecting the 'ecommerce' folder, Postman successfully connects the workspace to the file system (0:19). Agent Mode then prompts the user to 'Create with Agent Mode' (0:38) to generate a collection from the file system. The AI successfully creates an 'ecommerce FS APIs' collection and imports three environments (dev, prod, staging) found in the local directory (0:45, 1:17). The collection includes endpoints like GET/POST for Products and Orders, and a Health Check. The AI automatically writes comprehensive tests for every request, visible in the 'Scripts' tab (1:49). When running the collection, 68 tests passed, but 3 failed. Agent Mode analyzes the failures and provides detailed 'Recommendations for fix failures' (2:56), suggesting specific code adjustments like updating test assertions or fixing environment variable references. The presenter implements the fixes and reruns the collection, resulting in all 68 tests passing, validating the entire end-to-end automation workflow from local code to tested Postman collection (3:09).

### Workspace Setup

- Connecting to local folder
- Selecting 'From local repository folder'
- Naming the workspace 'ecommerce'

### Agent Mode Generation

- Creating 'ecommerce FS APIs' collection automatically
- Importing 'dev', 'prod', and 'staging' environments
- Initial run results show 68 tests passed and 3 failed

### Test Generation Details

- Comprehensive tests written for every request, covering status codes (e.g., 200, 201), response body checks, header validation (Content-Type), and schema validation for created product data.

### AI Debugging and Fixes

- Agent Mode provides explicit recommendations for the three failing tests
- Suggestions include normalizing types when asserting environment variables and updating test logic for specific endpoints like 'Get Order by ID' and 'Create Order'.

### Final Validation

- After applying the AI-suggested fixes, rerunning the collection results in all 68 tests passing, completing the automation cycle.

![Screenshot at 0:03: Selecting the option to create a new workspace from a local repository folder within Postman's workspace menu.](https://ss.rapidrecap.app/screens/h2eoW99bRFk/00-00-03.png)
![Screenshot at 0:09: The file selection dialog opens, where the user navigates to and selects the root folder of the local Flask project.](https://ss.rapidrecap.app/screens/h2eoW99bRFk/00-00-09.png)
![Screenshot at 0:19: The workspace successfully connects to the file system, displaying the directory structure containing the 'app.py' file on the left sidebar.](https://ss.rapidrecap.app/screens/h2eoW99bRFk/00-00-19.png)
![Screenshot at 0:38: The prompt appears asking the user to 'Create with Agent Mode' to generate a Postman collection based on the local code files.](https://ss.rapidrecap.app/screens/h2eoW99bRFk/00-00-38.png)
![Screenshot at 0:51: The 'ecommerce FS APIs' collection is automatically generated, showing structured requests like 'Products' and 'Orders' endpoints.](https://ss.rapidrecap.app/screens/h2eoW99bRFk/00-00-51.png)
![Screenshot at 1:16: The import dialog appears, showing that Agent Mode detected three environment files \('dev.postman\_environment.json', 'prod.postman\_environment.json', 'staging.postman\_environment.json'\) ready for import.](https://ss.rapidrecap.app/screens/h2eoW99bRFk/00-01-16.png)
![Screenshot at 1:22: The 'Create Product' request is selected, showing the URL using the dynamic environment variable {{baseUrl}}.](https://ss.rapidrecap.app/screens/h2eoW99bRFk/00-01-22.png)
![Screenshot at 1:45: The 'Get all products' request is opened, displaying the extensive, AI-generated test suite in the 'Tests' \(Scripts\) tab on the right.](https://ss.rapidrecap.app/screens/h2eoW99bRFk/00-01-45.png)
![Screenshot at 2:51: The collection runner results show 68 tests passed and 3 tests failed, prompting Agent Mode for remediation suggestions.](https://ss.rapidrecap.app/screens/h2eoW99bRFk/00-02-51.png)
