Story 2.1: Validate & Test Workflows API
This guide explains how to run comprehensive validation tests for all 8 Workflows API methods against a live n8n instance.
You need access to a running n8n instance (v1.82.3 or later) with:
- API access enabled
- Valid API key with workflow management permissions
- Network accessibility from your test environment
# Install dependencies
npm install
# Build the project
npm run buildCreate or update .config.json in the project root:
{
"environments": {
"production": {
"n8n_host": "https://your-n8n-instance.com",
"n8n_api_key": "your_api_key_here"
},
"staging": {
"n8n_host": "https://staging-n8n.com",
"n8n_api_key": "staging_api_key"
}
},
"defaultEnv": "production"
}Create .env file in project root:
N8N_HOST=https://your-n8n-instance.com
N8N_API_KEY=your_api_key_here
MCP_PORT=3456Important: Provide the base URL without /api/v1. The server automatically appends /api/v1.
In one terminal:
npm startThe server should start on http://localhost:3456 (or your configured MCP_PORT).
Verify health:
curl http://localhost:3456/healthExpected response:
{"status":"ok"}In another terminal:
node test-workflows-validation.jsEdit test-workflows-validation.js to control which tests run:
const testFlags = {
runListWorkflowsTests: true, // GET /workflows
runGetWorkflowTests: true, // GET /workflows/{id}
runCreateWorkflowTests: true, // POST /workflows
runUpdateWorkflowTests: true, // PUT /workflows/{id}
runDeleteWorkflowTests: true, // DELETE /workflows/{id}
runActivateWorkflowTests: true, // PUT /workflows/{id}/activate
runDeactivateWorkflowTests: true, // PUT /workflows/{id}/deactivate
runExecuteWorkflowTests: true, // Execute workflow
runMultiInstanceTests: false, // Requires multi-instance config
runErrorHandlingTests: true, // Error scenarios
runCleanup: true // Delete test workflows after
};Enable detailed logging:
DEBUG=true node test-workflows-validation.jsThe validation suite includes 54+ comprehensive tests:
- ✓ List all workflows without filters
- ✓ Response structure validation
- ✓ Filter by active=true
- ✓ Filter by active=false
- ✓ Pagination with limit parameter
- ✓ Multi-instance routing
- ✓ Error handling (401, malformed params)
- ✓ Retrieve existing workflow by ID
- ✓ Complete structure validation
- ✓ Nodes and connections validation
- ✓ Multi-instance retrieval
- ✓ 404 error for non-existent ID
- ✓ Create minimal workflow (name only)
- ✓ Create complete workflow with nodes
- ✓ Create complex workflow (10+ nodes)
- ✓ Verify nodes and connections preserved
- ✓ Multi-instance creation
- ✓ Error handling (400 for invalid data)
- ✓ Update workflow name
- ✓ Update workflow structure
- ✓ Verify changes persisted
- ✓ Multi-instance update
- ✓ 404 error for non-existent workflow
- ✓ Error handling validation
- ✓ Delete existing workflow
- ✓ Verify deletion (workflow not retrievable)
- ✓ Multi-instance deletion
- ✓ 404 error for non-existent workflow
- ✓ Idempotency check
- ✓ Activate inactive workflow
- ✓ Verify active status changes
- ✓ Persistence validation
- ✓ Idempotency (activate already active)
- ✓ Multi-instance activation
- ✓ 404 error handling
- ✓ Deactivate active workflow
- ✓ Verify inactive status
- ✓ Idempotency check
- ✓ Multi-instance deactivation
- ✓ Error handling
- ✓ Known limitation: Manual trigger workflows
- ✓ Error handling for non-existent workflow
- ✓ Documentation vs implementation comparison
- ✓ List workflows from default instance
- ✓ List workflows from specific instance
- ✓ Instance isolation validation
- ✓ 401 Unauthorized (invalid API key)
- ✓ 404 Not Found (non-existent resources)
- ✓ 400 Bad Request (malformed data)
- ✓ Error response format consistency
- ✓ Multi-instance error handling
- ✓ Error message clarity
======================================================================
Workflows API Validation Test Suite - Story 2.1
======================================================================
[INFO] Testing 8 Workflows API methods against live n8n instance
[INFO] MCP Server: http://localhost:3456/mcp
--- Pre-flight Checks ---
[INFO] Server health: ok
--- Task 2: Validate list_workflows ---
[TEST] list_workflows - List all workflows: ✓ PASS - Found 15 workflows
[TEST] list_workflows - Response structure validation: ✓ PASS - All required fields present
[TEST] list_workflows - Filter active=true: ✓ PASS - 8 active workflows
...
======================================================================
Test Summary Report
======================================================================
Total tests executed: 54
Passed: 54 (100%)
Failed: 0
Skipped: 0
✓ ALL TESTS PASSED!
======================================================================
[TEST] create_workflow - Complete workflow: ✗ FAIL - Node/connection mismatch
======================================================================
Test Summary Report
======================================================================
Total tests executed: 54
Passed: 53 (98%)
Failed: 1
❌ Failed tests:
- create_workflow - Complete workflow
⚠️ 1 test(s) need attention
======================================================================
The test suite automatically tracks discrepancies between documentation and implementation:
⚠️ Validation Findings: 1
1. [execute_workflow] Manual trigger workflows cannot be executed via REST API - n8n v1.82.3 limitation
These findings are logged to help identify:
- Documentation inaccuracies
- Missing functionality
- API behavior differences
- Implementation gaps
Tests automatically clean up created workflows unless runCleanup: false.
All test workflows are prefixed with ValidationTest_ for easy identification.
Manual cleanup:
# List test workflows in n8n UI and delete manually
# Or use list_workflows tool to find and delete by name prefixTo test multi-instance routing:
- Configure multiple environments in
.config.json - Set
runMultiInstanceTests: truein test flags - Run tests
The suite will validate:
- Workflow isolation between instances
- Correct routing to specified instance
- Default instance fallback
- Invalid instance error handling
# Check if port is in use
lsof -i :3456
# Use different port
MCP_PORT=3457 npm startUpdate test config:
const config = {
mcpServerUrl: 'http://localhost:3457/mcp',
healthCheckUrl: 'http://localhost:3457/health',
...
};Verify n8n instance accessibility:
curl -H "X-N8N-API-KEY: your_api_key" https://your-n8n-instance.com/api/v1/workflowsEnsure your API key has permissions for:
- List workflows
- Create workflows
- Update workflows
- Delete workflows
- Activate/deactivate workflows
- Enable debug mode:
DEBUG=true node test-workflows-validation.js - Disable cleanup: Set
runCleanup: falseto inspect created workflows - Run individual test suites: Set specific flags to
falseto isolate issues - Check n8n version: Tests validated against n8n v1.82.3+
The validation tests complement existing tests:
# Run all tests
npm test # Jest unit tests
node test-mcp-tools.js # MCP tool integration tests
node test-comprehensive.js # Comprehensive integration tests
node test-workflows-validation.js # Workflows API validation (Story 2.1)Add to your CI pipeline:
# .github/workflows/test.yml
- name: Build project
run: npm run build
- name: Start MCP server
run: npm start &
- name: Wait for server
run: sleep 5
- name: Run validation tests
run: node test-workflows-validation.js
env:
N8N_HOST: ${{ secrets.N8N_HOST }}
N8N_API_KEY: ${{ secrets.N8N_API_KEY }}After running validation tests, you should have:
- Test Results: Pass/fail status for all 54 tests
- Validation Report: Any discrepancies between docs and implementation
- Coverage Metrics: Percentage of successful tests per API method
- Findings List: Documentation updates needed
After completing validation:
- Document findings in Story 2.1 Dev Agent Record
- Update validation report (Task 12)
- Address any failures found during testing
- Update documentation based on validation findings
- Proceed to Story 2.2 (Executions API validation)
- Story:
docs/stories/2.1.validate-workflows-api.md - Epic:
docs/epic-2-api-implementation-validation.md - API Docs:
docs/n8n-api-docs/10-WORKFLOWS-API.md - Implementation:
src/index.ts,src/services/n8nApiWrapper.ts