82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Create Todo-Based MVP Builder Workflow in n8n
|
|
"""
|
|
|
|
import json
|
|
import requests
|
|
import os
|
|
|
|
# Read API key
|
|
api_key_file = '/home/bam/.n8n_api_key'
|
|
with open(api_key_file, 'r') as f:
|
|
api_key = f.read().strip()
|
|
|
|
# API endpoint
|
|
url = 'https://n8n.oky.sh/api/v1/workflows'
|
|
|
|
# Headers
|
|
headers = {
|
|
'Content-Type': 'application/json',
|
|
'X-N8N-API-KEY': api_key
|
|
}
|
|
|
|
# Load workflow definition
|
|
with open('/home/bam/claude/mvp-factory/todo-mvp-builder-workflow.json', 'r') as f:
|
|
workflow_data = json.load(f)
|
|
|
|
# Create workflow
|
|
print("Creating workflow: 'Todo-Based MVP Builder'...")
|
|
response = requests.post(url, headers=headers, json=workflow_data)
|
|
|
|
print(f"Status Code: {response.status_code}")
|
|
|
|
# Check if workflow already exists (200) or created (201)
|
|
if response.status_code in [200, 201]:
|
|
workflow = response.json()
|
|
workflow_id = workflow.get('id')
|
|
print(f"\n✅ Workflow created successfully!")
|
|
print(f"ID: {workflow_id}")
|
|
|
|
# Get webhook URL
|
|
webhook_url = f"https://n8n.oky.sh/webhook/todo-mvp-builder"
|
|
print(f"\nWebhook URL: {webhook_url}")
|
|
|
|
# Activate workflow
|
|
print("\nActivating workflow...")
|
|
activate_response = requests.post(
|
|
f"{url}/{workflow_id}/activate",
|
|
headers=headers
|
|
)
|
|
|
|
if activate_response.status_code == 200:
|
|
print("✅ Workflow activated successfully!")
|
|
|
|
# Save workflow info
|
|
info = {
|
|
'workflow_id': workflow_id,
|
|
'workflow_name': 'Todo-Based MVP Builder',
|
|
'webhook_url': webhook_url,
|
|
'status': 'active'
|
|
}
|
|
|
|
with open('/home/bam/claude/mvp-factory/todo-workflow-info.json', 'w') as f:
|
|
json.dump(info, f, indent=2)
|
|
|
|
print(f"\nWorkflow info saved to: /home/bam/claude/mvp-factory/todo-workflow-info.json")
|
|
print("\n" + "="*60)
|
|
print("WORKFLOW READY!")
|
|
print("="*60)
|
|
print(f"Webhook URL: {webhook_url}")
|
|
print(f"Workflow ID: {workflow_id}")
|
|
print("\nTest with:")
|
|
print(f"curl -X POST {webhook_url} \\")
|
|
print(' -H "Content-Type: application/json" \\')
|
|
print(' -d \'{"repository": {"name": "test-project"}, "head_commit": {"message": "MVP Prompt: Create a test app"}}\'')
|
|
else:
|
|
print(f"❌ Failed to activate workflow: {activate_response.status_code}")
|
|
print(activate_response.text)
|
|
else:
|
|
print(f"❌ Failed to create workflow: {response.status_code}")
|
|
print(response.text)
|