createCollection
Create a Postman collection using the v2.1.0 schema format, optionally specifying the target workspace.
Instructions
Creates a collection using the Postman Collection v2.1.0 schema format. If workspace is not specified, creates in the oldest personal workspace.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspace | No | The workspace's ID | |
| collection | No | Collection object in Postman Collection v2.1.0 format |
Implementation Reference
- tools/postman_tools.py:124-132 (handler)The run_tool method of CreateCollectionTool that executes the collection creation logic by making a POST request to /collections with optional workspace parameter.
async def run_tool(self, args: dict) -> list[TextContent]: workspace = args.get("workspace") collection = args.get("collection", {}) params = {"workspace": workspace} if workspace else {} body = {"collection": collection} result = await postman_api_call("POST", "/collections", body=body, params=params) return [TextContent(type="text", text=json.dumps(result, indent=2))] - tools/postman_tools.py:105-122 (schema)The get_tool_description method of CreateCollectionTool that defines the tool's input schema (workspace ID and collection object in v2.1.0 format).
def get_tool_description(self) -> Tool: return Tool( name=self.name, description="Creates a collection using the Postman Collection v2.1.0 schema format. If workspace is not specified, creates in the oldest personal workspace.", inputSchema={ "type": "object", "properties": { "workspace": { "type": "string", "description": "The workspace's ID" }, "collection": { "type": "object", "description": "Collection object in Postman Collection v2.1.0 format" } }, }, ) - tools/postman_tools.py:1839-1839 (registration)Where CreateCollectionTool is instantiated and registered in the register_all_tools function.
CreateCollectionTool(), - tools/postman_tools.py:99-103 (registration)The CreateCollectionTool class definition and __init__ which sets the tool name to 'createCollection'.
class CreateCollectionTool(ToolHandler): """Create a new collection""" def __init__(self): super().__init__("createCollection") - tools/postman_tools.py:21-67 (helper)The postman_api_call helper function used by CreateCollectionTool.run_tool to make the actual HTTP request to the Postman API.
async def postman_api_call( method: str, endpoint: str, body: dict | None = None, params: dict | None = None, headers: dict | None = None ) -> dict: """Make an API call to Postman API""" if not POSTMAN_API_KEY: raise RuntimeError("POSTMAN_API_KEY environment variable is not set") url = f"{POSTMAN_BASE_URL}{endpoint}" # Prepare headers request_headers = { "X-Api-Key": POSTMAN_API_KEY, "Content-Type": "application/json", } if headers: request_headers.update(headers) async with httpx.AsyncClient(timeout=30.0) as client: try: response = await client.request( method=method, url=url, json=body, params=params, headers=request_headers ) response.raise_for_status() if response.status_code == 204: return {"success": True, "message": "Operation completed successfully"} return response.json() if response.content else {"success": True} except httpx.HTTPStatusError as e: error_detail = e.response.text try: error_json = e.response.json() error_detail = json.dumps(error_json, indent=2) except: pass raise RuntimeError(f"Postman API error ({e.response.status_code}): {error_detail}") except Exception as e: raise RuntimeError(f"Request failed: {str(e)}")