Exemple fără SDK
Integrări complete, de copiat, cu HTTP simplu.
Nu există SDK de instalat: API-ul e JSON simplu peste HTTPS. Exemplele folosesc fetch (Node 20+) și requests (Python 3).
Sincronizează răspunsurile completate în baza ta de date
// Sync completed responses into your database every few minutes (works on every plan).
// Env: MFORM_API_KEY (type "Read only"), FORM_ID (form_…)
const BASE = "https://mform.md/api/public/v1";
const headers = { Authorization: `Bearer ${process.env.MFORM_API_KEY}` };
async function get(url) {
for (let attempt = 0; attempt < 5; attempt++) {
const res = await fetch(url, { headers });
if (res.status === 429) { // respect Retry-After
await new Promise((r) => setTimeout(r, Number(res.headers.get("Retry-After") ?? 1) * 1000));
continue;
}
const json = await res.json();
if (!res.ok) throw new Error(`${json.error.code} (${json.error.request_id})`);
return json;
}
throw new Error("rate limited");
}
export async function syncSince(lastCompletedAt, save) {
const url = new URL(`${BASE}/responses`);
url.search = new URLSearchParams({ form_id: process.env.FORM_ID, status: "completed", include: "answers",
completed_after: lastCompletedAt, limit: "100" }).toString();
let page = await get(url);
const rows = [...page.data];
while (page.has_more) {
url.searchParams.set("cursor", page.next_cursor);
page = await get(url);
rows.push(...page.data);
}
rows.reverse(); // the API returns newest first
for (const r of rows) await save(r.id, r.completed_at, r.fields); // upsert on r.id
return rows.length ? rows[rows.length - 1].completed_at : lastCompletedAt;
}Receptor de webhook-uri
# Webhook receiver: verify, answer fast, dedupe on the event id.
# Env: MFORM_WEBHOOK_SECRET (whsec_…, shown once when the endpoint is created)
import hashlib, hmac, json, os, time
from flask import Flask, request
app = Flask(__name__)
seen = set() # use your database in production
def verify_mform_signature(raw: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
parts = [p.strip().split("=", 1) for p in (header or "").split(",") if "=" in p]
ts = next((v for k, v in parts if k == "t"), "")
if not (ts.isascii() and ts.isdigit()) or abs(time.time() - int(ts)) > tolerance:
return False
expected = hmac.new(secret.encode(), ts.encode() + b"." + raw, hashlib.sha256).hexdigest()
# compare bytes: compare_digest raises TypeError on non-ASCII str
return any(k == "v1" and hmac.compare_digest(v.encode(), expected.encode()) for k, v in parts)
@app.post("/webhooks/mform")
def mform_webhook():
raw = request.get_data() # the raw body, before any JSON parsing
if not verify_mform_signature(raw, request.headers.get("Mform-Signature", ""), os.environ["MFORM_WEBHOOK_SECRET"]):
return "", 400
event = json.loads(raw)
if event["id"] in seen:
return "", 200
seen.add(event["id"])
if event["type"] == "response.completed":
response = event["data"]["object"]
print(response["id"], response.get("fields")) # hand it to a queue
return "", 200Linkuri personalizate din CRM
# From a CRM: create a form once (template questions + a "Company" question),
# then a personalised link per lead with the company prefilled (Pro+, forms:write).
import os, uuid, requests
BASE = "https://mform.md/api/public/v1"
H = {"Authorization": f"Bearer {os.environ['MFORM_API_KEY']}"}
form = requests.post(f"{BASE}/forms", headers={**H, "Idempotency-Key": str(uuid.uuid4())}, timeout=30, json={
"template_id": "tpl_nps-survey", "title": "NPS Q4", "publish": True,
"questions": [{"text": "Company", "type": "short_text"}], # added after the template's questions
})
form.raise_for_status()
form = form.json()
company = next(q["id"] for q in form["questions"] if q["text"] == "Company") # qst_…
def link_for(lead_name: str) -> str:
r = requests.post(f"{BASE}/forms/{form['id']}/share_links", headers=H, timeout=30,
json={"utm_source": "crm", "prefill": {company: lead_name}, "expires_in_days": 14})
r.raise_for_status()
return r.json()["url"]
print(link_for("ACME SRL"))Recuperare după o pană
# What did my receiver miss during the outage? (events are kept 30 days)
curl "https://mform.md/api/public/v1/events?type=response.completed&created_after=2026-11-27T08:00:00Z&limit=100" \
-H "Authorization: Bearer $MFORM_API_KEY"
# Or re-send failed deliveries of one endpoint (webhooks:manage, Business+)
curl "https://mform.md/api/public/v1/webhook_endpoints/we_…/deliveries?status=abandoned" -H "Authorization: Bearer $MFORM_API_KEY"
curl -X POST "https://mform.md/api/public/v1/webhook_endpoints/we_…/deliveries/wd_…/retry" -H "Authorization: Bearer $MFORM_API_KEY"