REST API pentru a integra Megaforms cu sistemele tale. OpenAPI 3.1 spec.
Endpoint-urile autentificate folosesc cookie HTTP-only megaforms_token setat după signup/login. Pentru integrări server-to-server, login programatic și păstrează cookie-ul în sesiunea ta.
# Login programatic
curl -X POST https://forms.megapromoting.com/api/auth/login \
-H 'Content-Type: application/json' \
-c cookies.txt \
-d '{"email":"you@example.com","password":"..."}'
# Use the cookie pentru API calls
curl https://forms.megapromoting.com/api/questionnaires -b cookies.txt# 1. Pornește o sesiune nouă
curl -X POST https://forms.megapromoting.com/api/public/q/SLUG/sessions \
-H 'Content-Type: application/json' \
-d '{"name":"Ion","email":"ion@example.ro","loaded_at":1715789000000}'
# → { "sessionId": 42 }
# 2. Trimite un răspuns la întrebarea cu id=7
curl -X POST https://forms.megapromoting.com/api/public/q/SLUG/sessions/42/answers \
-H 'Content-Type: application/json' \
-d '{"questionId":7,"answerText":"Răspuns text"}'
# → { "success": true, "isComplete": false, "progress": { "answered": 1, "total": 10 } }
# 3. Continuă cu fiecare răspuns. Când isComplete=true, sesiunea e finalizată
# automat și se declanșează webhook session.completed.Configurează webhook-uri în Settings → Webhooks. Fiecare delivery e semnată HMAC-SHA256 cu un secret per workspace.
# Verificare semnătură în Node.js
const crypto = require('crypto');
const expected = crypto
.createHmac('sha256', WEBHOOK_SECRET)
.update(rawBody)
.digest('hex');
const received = request.headers['x-megaforms-signature'];
if (expected !== received) throw new Error('Invalid signature');
# Events disponibile
session.started # Sesiune nouă creată
answer.submitted # Răspuns nou la o întrebare
session.completed # Sesiune finalizată (toate Q-urile răspunse)Acum disponibil: OpenAPI 3.1 spec. SDK-uri TypeScript / Python / Go vin pe roadmap (sprint S13+).
Între timp, generează un client din OpenAPI cu:
# TypeScript npx @openapitools/openapi-generator-cli generate \ -i https://forms.megapromoting.com/api/openapi \ -g typescript-fetch -o ./megaforms-client # Python openapi-python-client generate --url https://forms.megapromoting.com/api/openapi