87 lines
2.4 KiB
Bash
87 lines
2.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Version inline avec paramètres
|
|
# Usage: ./test-n8n-inline.sh [MISSION_ID] [PROJECT_NAME]
|
|
|
|
MISSION_ID="${1:-3103ec1a-acde-4025-9ead-4e1a0ddc047c}"
|
|
PROJECT_NAME="${2:-SEFFIR}"
|
|
|
|
python3 << EOF
|
|
import urllib.request
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
# Charger .env.local
|
|
env_vars = {}
|
|
if os.path.exists('.env.local'):
|
|
with open('.env.local') as f:
|
|
for line in f:
|
|
if '=' in line and not line.strip().startswith('#'):
|
|
key, value = line.strip().split('=', 1)
|
|
env_vars[key] = value
|
|
|
|
webhook_url = "https://brain.slm-lab.net/webhook-test/mission-created"
|
|
mission_id = "${MISSION_ID}"
|
|
project_name = "${PROJECT_NAME}"
|
|
api_key = env_vars.get('N8N_API_KEY', os.environ.get('N8N_API_KEY'))
|
|
api_url = env_vars.get('NEXT_PUBLIC_API_URL', os.environ.get('NEXT_PUBLIC_API_URL', 'https://hub.slm-lab.net/api'))
|
|
|
|
if not api_key:
|
|
print("❌ Erreur: N8N_API_KEY n'est pas définie")
|
|
sys.exit(1)
|
|
|
|
print(f"🧪 Test du webhook N8N")
|
|
print(f"Mission ID: {mission_id}")
|
|
print(f"Project Name: {project_name}")
|
|
print("")
|
|
|
|
data = {
|
|
"name": project_name,
|
|
"oddScope": ["odd-4"],
|
|
"niveau": "s",
|
|
"intention": "",
|
|
"missionType": "remote",
|
|
"donneurDOrdre": "group",
|
|
"projection": "long",
|
|
"services": [],
|
|
"participation": "ouvert",
|
|
"profils": [],
|
|
"guardians": {},
|
|
"volunteers": [],
|
|
"creatorId": "203cbc91-61ab-47a2-95d2-b5e1159327d7",
|
|
"missionId": mission_id,
|
|
"logoPath": f"missions/{mission_id}/logo.png",
|
|
"logoUrl": f"https://hub.slm-lab.net/api/missions/image/missions/{mission_id}/logo.png",
|
|
"config": {
|
|
"N8N_API_KEY": api_key,
|
|
"MISSION_API_URL": api_url
|
|
}
|
|
}
|
|
|
|
req = urllib.request.Request(
|
|
webhook_url,
|
|
data=json.dumps(data).encode('utf-8'),
|
|
headers={'Content-Type': 'application/json'}
|
|
)
|
|
|
|
try:
|
|
with urllib.request.urlopen(req) as response:
|
|
print(f"✅ Status: {response.status} {response.reason}")
|
|
print(f"📄 Réponse:")
|
|
response_data = json.loads(response.read().decode('utf-8'))
|
|
print(json.dumps(response_data, indent=2))
|
|
except urllib.error.HTTPError as e:
|
|
print(f"❌ HTTP Error {e.code}: {e.reason}")
|
|
try:
|
|
error_body = e.read().decode('utf-8')
|
|
print(f"📄 Corps de l'erreur:")
|
|
print(json.dumps(json.loads(error_body), indent=2))
|
|
except:
|
|
print(error_body)
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
print(f"❌ Erreur: {e}")
|
|
sys.exit(1)
|
|
EOF
|