توثيق API — فاتورة EMM

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

المصادقة

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

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

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

  • الحد: 60 طلباً/دقيقة لكل مفتاح؛ بعدها 429 مع ترويسة Retry-After بالثواني.
  • النجاح: {"ok":true,"data":…} · الخطأ: {"ok":false,"error":{"code":"…","message":"…"}}
  • القوائم: ?limit=N (من 1 إلى 200، الافتراضي 50) و?offset=N؛ النتيجة data.items وdata.total.
  • المبالغ نص بالريال بمنزلتين ("1611.15")، العملة SAR، الطوابع الزمنية ISO-8601 بتوقيت +03:00، التواريخ YYYY-MM-DD ميلادية.
  • حصة الخطة المجانية 3 فواتير/شهر: الإنشاء فوقها → 409 quota_exceeded. لا تُحصَّل مدفوعات عبر الـ API: العميل يدفع من رابط الفاتورة عبر StreamPay.
  • حمولة QR الزاتكاوية (TLV base64) في كل فاتورة وفي GET /invoices/{id}/zatca — المرحلة الأولى فقط (لا ربط مع منصة فاتورة).

نقاط الاتصال

الحساب / Account

GET /api/v1/me

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

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

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

GET /api/v1/plan

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

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

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

GET /api/v1/quota

حصة الشهر / Monthly quota

عدد الفواتير المنشأة هذا الشهر ميلادياً وحد الخطة (3 للمجاني، غير محدود لـ Pro). Invoices created this Gregorian month and the plan limit. · الصلاحية: read

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

العملاء / Clients

GET /api/v1/clients

العملاء / Clients

قائمة العملاء مع بحث وترقيم صفحات. Lists clients with search and pagination. · المعاملات: q limit offset · الصلاحية: read

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

POST /api/v1/clients

إضافة عميل / Add client

عميل باسم (مطلوب) وبريد وهاتف ورقم ضريبي وعنوان. Client with name (required), email, phone, VAT number (15 digits 3…3 when given) and address. · الصلاحية: write

curl -X POST "https://invoice.emm.sa/api/v1/clients" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"شركة العميل التجريبي","email":"accounts@client.sa","phone":"0551234567","vat_number":"310987654300003","address":"الرياض — حي العليا"}'

GET /api/v1/clients/{id}

عميل / Client

عميل واحد بالمعرّف. One client by id. · المعاملات: id* · الصلاحية: read

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

PUT /api/v1/clients/{id}

تعديل عميل / Update client

تعديل بيانات العميل (استبدال كامل للحقول المرسلة). Replaces the client's fields. · المعاملات: id* · الصلاحية: write

curl -X PUT "https://invoice.emm.sa/api/v1/clients/{id}" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"شركة العميل التجريبي","email":"accounts@client.sa","phone":"0551234567","vat_number":"310987654300003","address":"الرياض — حي العليا"}'

DELETE /api/v1/clients/{id}

حذف عميل / Delete client

يحذف عميلاً بلا فواتير (409 in_use). Deletes a client without invoices (409 otherwise). · المعاملات: id* · الصلاحية: admin

curl -X DELETE "https://invoice.emm.sa/api/v1/clients/{id}" \
  -H "Authorization: Bearer $EMM_KEY"

الفواتير / Invoices

GET /api/v1/invoices

الفواتير / Invoices

فواتير المنشأة مع فلتر status (draft|sent|paid|overdue) وclient_id وترقيم صفحات. Invoices with status/client filters and pagination. · المعاملات: status client_id limit offset · الصلاحية: read

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

POST /api/v1/invoices

إنشاء فاتورة / Create invoice

تنشئ فاتورة زاتكا مبسطة (مسودة، أو مرسلة مع send=true) ضمن حصة الشهر (409 quota_exceeded). المبالغ نص بالريال. Creates a ZATCA simplified invoice (draft, or sent with send=true) within the monthly quota. · الصلاحية: write

curl -X POST "https://invoice.emm.sa/api/v1/invoices" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"client_id":1,"due_date":"2026-12-16","notes":"الدفع خلال 14 يوماً","items":[{"description":"تصميم شعار","qty":"1","unit_price":"1000","discount":"100"},{"description":"طباعة","qty":"2","unit_price":"250.5","discount":"0"}]}'

GET /api/v1/invoices/{id}

فاتورة / Invoice

فاتورة كاملة: البنود، الإجماليات، UUID، رمز QR (TLV base64)، رابط المشاركة. One invoice with items, totals, UUID, ZATCA QR payload and share link. · المعاملات: id* · الصلاحية: read

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

PUT /api/v1/invoices/{id}

تعديل فاتورة / Update invoice

تعديل البنود والعميل وتاريخ الاستحقاق والضريبة والملاحظات — مسودة أو مرسلة فقط (409 locked للمدفوعة). Replaces lines and header fields of a non-paid invoice. · المعاملات: id* · الصلاحية: write

curl -X PUT "https://invoice.emm.sa/api/v1/invoices/{id}" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"client_id":1,"due_date":"2026-12-16","notes":"الدفع خلال 14 يوماً","items":[{"description":"تصميم شعار","qty":"1","unit_price":"1000","discount":"100"},{"description":"طباعة","qty":"2","unit_price":"250.5","discount":"0"}]}'

POST /api/v1/invoices/{id}/status

تغيير الحالة / Transition

status: sent (اعتماد للإرسال) | paid (تعليم كمدفوعة، مع paid_at وpayment_ref اختيارياً) — يتخطى الحالة المدفوعة. sent / paid; paid invoices are final. · المعاملات: id* · الصلاحية: write

curl -X POST "https://invoice.emm.sa/api/v1/invoices/{id}/status" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"status":"paid","paid_at":"","payment_ref":"TRF-1200"}'

POST /api/v1/invoices/{id}/mark-paid

تعليم كمدفوعة / Mark paid

اختصار لتغيير الحالة إلى paid مع مرجع دفع اختياري. Shortcut for status=paid with an optional payment reference. · المعاملات: id* · الصلاحية: write

curl -X POST "https://invoice.emm.sa/api/v1/invoices/{id}/mark-paid" \
  -H "Authorization: Bearer $EMM_KEY" \
  -H "Content-Type: application/json" \
  -d '{"paid_at":"","payment_ref":"TRF-1200"}'

DELETE /api/v1/invoices/{id}

حذف مسودة / Delete draft

يحذف المسودات فقط (409 not_draft لغيرها). Deletes drafts only. · المعاملات: id* · الصلاحية: admin

curl -X DELETE "https://invoice.emm.sa/api/v1/invoices/{id}" \
  -H "Authorization: Bearer $EMM_KEY"

GET /api/v1/invoices/{id}/zatca

حمولة QR الزاتكاوية / ZATCA QR payload

الحقائق الخمسة بترميز TLV: اسم البائع، الرقم الضريبي، الطابع الزمني +03:00، الإجمالي شامل الضريبة، مبلغ الضريبة + base64 وصورة PNG. The five TLV tags plus base64 and a PNG data URI. · المعاملات: id* · الصلاحية: read

curl -X GET "https://invoice.emm.sa/api/v1/invoices/{id}/zatca" \
  -H "Authorization: Bearer $EMM_KEY"

GET /api/v1/invoices/{id}/share

رابط المشاركة / Public share link

الرابط العام للفاتورة، رابط الطباعة، ونص واتساب جاهز مع رابط wa.me. Public URL, print URL and a ready WhatsApp reminder with its wa.me link. · المعاملات: id* · الصلاحية: read

curl -X GET "https://invoice.emm.sa/api/v1/invoices/{id}/share" \
  -H "Authorization: Bearer $EMM_KEY"

التذكيرات / Reminders

GET /api/v1/reminders

قائمة التذكيرات / Payment reminders

الفواتير غير المدفوعة (المتأخرة أولاً) مع نص تذكير ورابط واتساب لكل منها — ميزة Pro (403 plan_required). Unpaid invoices with a reminder text + wa.me link each — Pro feature. · المعاملات: limit offset · الصلاحية: read

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

MCP

نفس المفتاح، POST إلى https://invoice.emm.sa/mcp (JSON-RPC 2.0، Streamable HTTP): initialize ← notifications/initialized ← tools/list ← tools/call. الأدوات: invoice_capabilities invoice_pricing invoice_clients invoice_list invoice_get invoice_create invoice_mark_paid . مثال كامل في دليل الوكلاء.