توثيق API — نماذج EMM

REST فوق HTTPS بمصادقة مفتاح API. الإصدار 1.0.0 · openapi.json · خادم MCP · ملخص للنماذج

المصادقة

أنشئ مفتاحاً من صفحة المفاتيح (تسجيل الدخول مطلوب). أرسله في كل طلب:

Authorization: Bearer emm_form_...xxxx
# أو
X-API-Key: emm_form_...xxxx
  • بلا مفتاح أو مفتاح غير صالح/ملغى → 401
  • مفتاح بلا صلاحية للعملية → 403
  • الصلاحيات: read للقراءة والتصدير، write للإنشاء والتعديل والمراجعة والـWebhooks، admin للحذف.

الحدود والصيغة

  • الحد: 60 طلباً/دقيقة لكل مفتاح؛ بعدها 429 مع ترويسة Retry-After بالثواني.
  • النجاح: {"ok":true,"data":…} · الخطأ: {"ok":false,"error":{"code":"…","message":"…"}}
  • القوائم: ?limit=N (من 1 إلى 200، الافتراضي 50) و?offset=N؛ النتيجة data.items وdata.total.
  • المبالغ نص بالريال بمنزلتين ("50.00")، العملة SAR، التواريخ ISO-8601 بتوقيت +03:00.
  • لا تُحصَّل مدفوعات عبر الـ API: رسم التقديم يدفعه المتقدّم من النموذج العام عبر StreamPay، والتحقق من الدفع على الخادم.

نقاط الاتصال

GEThttps://form.emm.sa/api/v1/me

الهوية والخطة والحدود / Identity, plan, quotas

يتحقق من المفتاح ويعيد المستخدم والخطة الحالية وحدود النماذج والردود الشهرية. Checks a key; returns user, current plan and quotas. · الصلاحية: read

curl -X GET "https://form.emm.sa/api/v1/me" \
  -H "Authorization: Bearer $EMM_KEY"
{"plan":{"api":true,"csv_export":false,"currency":"SAR","features":["نموذج واحد","100 رد شهرياً","بدون رسوم","11 نوع حقل مع التحقق","منطق شرطي (تخطي الأسئلة)","REST API وMCP وWebhooks (متاحة في كل الخطط)"],"id":"free","limits":{"forms":1,"monthly_responses":100},"name":"مجاني","paid_applications":false,"period":"month","price":"0.00"},"quotas":{"forms":{"limit":1,"used":0},"responses":{"limit":100,"month":"2026-12","used":4}},"service":"form","user":{"email":"user@example.com","org_name":"جهة"}}

GEThttps://form.emm.sa/api/v1/plan

الخطة الحالية وكل الخطط / Current plan and catalogue

الخطة الحالية مع الاستهلاك، وكل الخطط بأسعارها وحدودها. Current plan with usage plus every plan (SAR/month). · الصلاحية: read

curl -X GET "https://form.emm.sa/api/v1/plan" \
  -H "Authorization: Bearer $EMM_KEY"

GEThttps://form.emm.sa/api/v1/forms

النماذج / Forms

قائمة نماذجك مع عدد الردود والمعلّقة. Lists your forms with response counts. · المعاملات: limit offset status · الصلاحية: read

curl -X GET "https://form.emm.sa/api/v1/forms?limit=50&offset=0&status=" \
  -H "Authorization: Bearer $EMM_KEY"

POSThttps://form.emm.sa/api/v1/forms

إنشاء نموذج / Create form

ينشئ نموذجاً (ضمن حد الخطة) مع حقول اختيارية. Creates a form within the plan limit (409 quota_exceeded), optionally with its fields. · الصلاحية: write

curl -X POST "https://form.emm.sa/api/v1/forms" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title":"طلب منحة","slug":"grant","description":"نموذج تقديم على المنحة","fee":"0.00","max_submissions":200,"status":"open","fields":[{"type":"short","label":"الاسم الكامل","required":true},{"type":"national_id","label":"الهوية","required":true},{"type":"phone","label":"جوال","required":true},{"type":"select","label":"الفئة","options":["طالب","موظف"]},{"type":"file","label":"السيرة الذاتية","cond_index":3,"cond_value":"طالب"}]}'
{"close_at":"","currency":"SAR","fee":"0.00","fields":[{"id":7,"label":"الاسم الكامل","options":[],"required":true,"type":"short"}],"id":3,"max_submissions":200,"open_at":"","pending_count":2,"public_url":"https://form.emm.sa/f/grant","slug":"grant","status":"open","submissions_count":12,"title":"طلب منحة"}

GEThttps://form.emm.sa/api/v1/forms/{id}

نموذج / Form

نموذج واحد بحقوله. One form with its fields. · المعاملات: id* · الصلاحية: read

curl -X GET "https://form.emm.sa/api/v1/forms/{id}" \
  -H "Authorization: Bearer $EMM_KEY"
{"close_at":"","currency":"SAR","fee":"0.00","fields":[{"id":7,"label":"الاسم الكامل","options":[],"required":true,"type":"short"}],"id":3,"max_submissions":200,"open_at":"","pending_count":2,"public_url":"https://form.emm.sa/f/grant","slug":"grant","status":"open","submissions_count":12,"title":"طلب منحة"}

PATCHhttps://form.emm.sa/api/v1/forms/{id}

تعديل نموذج / Update form

تعديل جزئي (العنوان، الرابط، الرسم، التواريخ، الحد الأقصى، الحالة، اللون). fields عند إرسالها: عنصر بـ id يعدّل الحقل، وبلا id يضيفه (لا يحذف شيئاً). Partial update; fields sync (update by id, create without id). · المعاملات: id* · الصلاحية: write

curl -X PATCH "https://form.emm.sa/api/v1/forms/{id}" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title":"طلب منحة 2027","fee":"50.00","close_at":"2027-01-31"}'
{"close_at":"","currency":"SAR","fee":"0.00","fields":[{"id":7,"label":"الاسم الكامل","options":[],"required":true,"type":"short"}],"id":3,"max_submissions":200,"open_at":"","pending_count":2,"public_url":"https://form.emm.sa/f/grant","slug":"grant","status":"open","submissions_count":12,"title":"طلب منحة"}

POSThttps://form.emm.sa/api/v1/forms/{id}/open

فتح النموذج / Open form

يفتح النموذج لاستقبال الردود. Opens the form for submissions. · المعاملات: id* · الصلاحية: write

curl -X POST "https://form.emm.sa/api/v1/forms/{id}/open" \
  -H "Authorization: Bearer $EMM_KEY"
{"close_at":"","currency":"SAR","fee":"0.00","fields":[{"id":7,"label":"الاسم الكامل","options":[],"required":true,"type":"short"}],"id":3,"max_submissions":200,"open_at":"","pending_count":2,"public_url":"https://form.emm.sa/f/grant","slug":"grant","status":"open","submissions_count":12,"title":"طلب منحة"}

POSThttps://form.emm.sa/api/v1/forms/{id}/close

إغلاق النموذج / Close form

يغلق النموذج فوراً. Closes the form immediately. · المعاملات: id* · الصلاحية: write

curl -X POST "https://form.emm.sa/api/v1/forms/{id}/close" \
  -H "Authorization: Bearer $EMM_KEY"
{"close_at":"","currency":"SAR","fee":"0.00","fields":[{"id":7,"label":"الاسم الكامل","options":[],"required":true,"type":"short"}],"id":3,"max_submissions":200,"open_at":"","pending_count":2,"public_url":"https://form.emm.sa/f/grant","slug":"grant","status":"open","submissions_count":12,"title":"طلب منحة"}

POSThttps://form.emm.sa/api/v1/forms/{id}/duplicate

تكرار النموذج / Duplicate form

ينسخ النموذج بحقوله إلى نموذج جديد مفتوح. Copies the form with its fields (409 quota_exceeded on the free plan). · المعاملات: id* · الصلاحية: write

curl -X POST "https://form.emm.sa/api/v1/forms/{id}/duplicate" \
  -H "Authorization: Bearer $EMM_KEY"
{"close_at":"","currency":"SAR","fee":"0.00","fields":[{"id":7,"label":"الاسم الكامل","options":[],"required":true,"type":"short"}],"id":3,"max_submissions":200,"open_at":"","pending_count":2,"public_url":"https://form.emm.sa/f/grant","slug":"grant","status":"open","submissions_count":12,"title":"طلب منحة"}

POSThttps://form.emm.sa/api/v1/forms/{id}/fields

إضافة حقل / Add field

يضيف حقلآ في نهاية النموذج بنفس تحقق المنشئ. Appends a field (same validation as the builder). · المعاملات: id* · الصلاحية: write

curl -X POST "https://form.emm.sa/api/v1/forms/{id}/fields" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type":"short","label":"الاسم الكامل","required":true}'
{"conditional":null,"help":"","id":7,"label":"الاسم الكامل","options":[],"position":0,"required":true,"type":"short"}

PATCHhttps://form.emm.sa/api/v1/forms/{id}/fields/{fid}

تعديل حقل / Update field

يعدّل نوع الحقل وعنوانه وخياراته وشرطه. Updates type, label, help, required, options and condition. · المعاملات: id* fid* · الصلاحية: write

curl -X PATCH "https://form.emm.sa/api/v1/forms/{id}/fields/{fid}" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type":"short","label":"الاسم الكامل","required":true}'
{"conditional":null,"help":"","id":7,"label":"الاسم الكامل","options":[],"position":0,"required":true,"type":"short"}

DELETEhttps://form.emm.sa/api/v1/forms/{id}/fields/{fid}

حذف حقل / Delete field

يحذف الحقل (الردود السابقة تبقى محفوظة). Deletes a field; past answers stay stored. · المعاملات: id* fid* · الصلاحية: admin

curl -X DELETE "https://form.emm.sa/api/v1/forms/{id}/fields/{fid}" \
  -H "Authorization: Bearer $EMM_KEY"
{"data":{"deleted":true},"ok":true}

GEThttps://form.emm.sa/api/v1/submissions

الردود / Submissions

ردودك مع فلاتر form_id وpayment (paid|pending|none) وreview وq (بحث). Submissions with form/payment/review filters and free-text search. · المعاملات: form_id payment review q limit offset · الصلاحية: read

curl -X GET "https://form.emm.sa/api/v1/submissions?form_id=&payment=&review=&q=&limit=50&offset=0" \
  -H "Authorization: Bearer $EMM_KEY"

GEThttps://form.emm.sa/api/v1/submissions.csv

تصدير CSV / CSV export

نفس فلاتر القوائم؛ يتطلب خطة مؤسسة (403). Same filters as the list; org plan only (403). · المعاملات: form_id payment review · الصلاحية: read

curl -X GET "https://form.emm.sa/api/v1/submissions.csv?form_id=&payment=&review=" \
  -H "Authorization: Bearer $EMM_KEY"

GEThttps://form.emm.sa/api/v1/submissions/{id}

رد / Submission

رد واحد بالإجابات المرتبة والمراجعة والمرفقات. One submission with ordered answers, review state and files. · المعاملات: id* · الصلاحية: read

curl -X GET "https://form.emm.sa/api/v1/submissions/{id}" \
  -H "Authorization: Bearer $EMM_KEY"
{"answers":[{"field_id":7,"label":"الاسم الكامل","type":"short","value":"أحمد"}],"currency":"SAR","fee":"50.00","files":[],"form":{"id":3,"slug":"grant","title":"طلب منح"},"id":9,"note":"","paid_at":"2026-12-03T10:16:02+03:00","payment":"paid","reference":"FM-7K3M9Q","review":"under_review","state":"submitted","submitted_at":"2026-12-03T10:15:00+03:00"}

PATCHhttps://form.emm.sa/api/v1/submissions/{id}

مراجعة / Review

review: under_review | accepted | rejected + note (حتى 2000 حرف) — للردود المكتملة فقط (409). Set the review status and internal note (409 while unpaid). · المعاملات: id* · الصلاحية: write

curl -X PATCH "https://form.emm.sa/api/v1/submissions/{id}" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"review":"accepted","note":"مستندات مكتملة"}'
{"answers":[{"field_id":7,"label":"الاسم الكامل","type":"short","value":"أحمد"}],"currency":"SAR","fee":"50.00","files":[],"form":{"id":3,"slug":"grant","title":"طلب منح"},"id":9,"note":"","paid_at":"2026-12-03T10:16:02+03:00","payment":"paid","reference":"FM-7K3M9Q","review":"under_review","state":"submitted","submitted_at":"2026-12-03T10:15:00+03:00"}

GEThttps://form.emm.sa/api/v1/public-forms/{slug}

النموذج العام / Public form

ما يراه المتقدّم في /f/{slug}: الحقول العامة والرسم وهل يستقبل ردوداً الآن. What the applicant sees on /f/{slug}. · المعاملات: slug* · الصلاحية: read

curl -X GET "https://form.emm.sa/api/v1/public-forms/{slug}" \
  -H "Authorization: Bearer $EMM_KEY"
{"accepts_submissions":true,"currency":"SAR","description":"","fee":"0.00","fields":[{"id":7,"label":"الاسم الكامل","required":true,"type":"short"}],"org_name":"جهة","public_url":"https://form.emm.sa/f/grant","slug":"grant","status":"open","title":"طلب منحة"}

GEThttps://form.emm.sa/api/v1/webhooks

Webhooks الصادرة / Outgoing webhooks

قائمة عناوين الـWebhook المسجّلة (لكل نموذج أو لكل النماذج). Lists registered webhook endpoints. · المعاملات: limit offset · الصلاحية: read

curl -X GET "https://form.emm.sa/api/v1/webhooks?limit=50&offset=0" \
  -H "Authorization: Bearer $EMM_KEY"

POSThttps://form.emm.sa/api/v1/webhooks

تسجيل Webhook / Register webhook

يسجّل https URL مع سر HMAC (أو يولّده) لحدث submission.paid — form_id = 0 لكل نماذجك. Registers a URL + HMAC secret for paid submissions. · الصلاحية: write

curl -X POST "https://form.emm.sa/api/v1/webhooks" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/hooks/emm"}'
{"active":true,"created_at":"2026-12-03T12:00:00+03:00","event":"submission.paid","form_id":0,"id":1,"secret":"whsec_…","url":"https://example.com/hooks/emm"}

GEThttps://form.emm.sa/api/v1/webhooks/{id}

Webhook / Webhook

تفاصيل التسجيل مع السر. Registration details with the secret. · المعاملات: id* · الصلاحية: read

curl -X GET "https://form.emm.sa/api/v1/webhooks/{id}" \
  -H "Authorization: Bearer $EMM_KEY"
{"active":true,"created_at":"2026-12-03T12:00:00+03:00","event":"submission.paid","form_id":0,"id":1,"secret":"whsec_…","url":"https://example.com/hooks/emm"}

DELETEhttps://form.emm.sa/api/v1/webhooks/{id}

حذف Webhook / Delete webhook

يحذف التسجيل (مع سجل التسليم). Deletes the registration and its delivery log. · المعاملات: id* · الصلاحية: admin

curl -X DELETE "https://form.emm.sa/api/v1/webhooks/{id}" \
  -H "Authorization: Bearer $EMM_KEY"
{"data":{"deleted":true},"ok":true}

POSThttps://form.emm.sa/api/v1/webhooks/{id}/test

اختبار Webhook / Test delivery

يرسل حدث webhook.test الآن ويعيد نتيجة التسليم. Sends a webhook.test event now and returns the delivery result. · المعاملات: id* · الصلاحية: write

curl -X POST "https://form.emm.sa/api/v1/webhooks/{id}/test" \
  -H "Authorization: Bearer $EMM_KEY"
{"attempt":1,"created_at":"2026-12-03T12:00:00+03:00","duration_ms":120,"event":"webhook.test","id":5,"ok":true,"response":"ok","status_code":200,"webhook_id":1}

GEThttps://form.emm.sa/api/v1/webhooks/{id}/deliveries

سجل التسليم / Delivery log

آخر 100 محاولة تسليم (الحالة والاستجابة والمدة). Last 100 delivery attempts with status, response and duration. · المعاملات: id* · الصلاحية: read

curl -X GET "https://form.emm.sa/api/v1/webhooks/{id}/deliveries" \
  -H "Authorization: Bearer $EMM_KEY"

Webhooks الصادرة (موقّعة)

سجّل POST /api/v1/webhooks بـ {"url":"https://…","form_id":0,"secret":"whsec_…"}. عند نجاح دفع أي طلب نرسل POST JSON مع:

X-EMM-Event: submission.paid
X-EMM-Webhook-Id: 1
X-EMM-Signature: t=1764750000,v1=5257a8…

v1 = hex(HMAC-SHA256(secret, t + "." + raw_body)). تحقق في ثابت الوقت وارفض إن كان t أقدم من 5 دقائق. 3 محاولات (0s · 5s · 30s)، 2xx = نجاح، السجل في GET /webhooks/{id}/deliveries.

# التحقق من التوقيع (أي لغة): HMAC-SHA256(secret, t + "." + raw_body) == v1
# Python:
import hmac, hashlib
def verify(secret, header, body):
    parts = dict(p.split("=", 1) for p in header.split(","))
    mac = hmac.new(secret.encode(), f"{parts['t']}.".encode() + body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(mac, parts["v1"])

MCP

نفس المفتاح، POST إلى https://form.emm.sa/mcp (JSON-RPC 2.0, Streamable HTTP): initialize ← notifications/initialized ← tools/list ← tools/call. الأدوات: form_capabilities, form_pricing, form_list, form_submissions, form_create, form_update, form_review. مثال كامل في دليل الوكلاء.