زاجلي
زاجلي

التواصل متعدد القنوات

Zagaly logo
زاجلي
زاجلي
إظهار/إخفاء الشريط الجانبي

أدوات المطور

مرجع واجهة برمجة التطبيقات والويب هوكس

أرسل الرسائل، وأدرِ جهات الاتصال، وشغّل الحملات، وتلقّى الأحداث الفورية عبر جميع القنوات من أي لغة برمجة.

المصادقة

تستخدم واجهة برمجة التطبيقات v1 مصادقة زوج المفاتيح. يجب أن يتضمن كل طلب ترويستي HTTP مخصّصتين. قم بإنشاء مفاتيحك من مفاتيح API.

http
X-Public-Key: pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        X-Secret-Key: sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        Content-Type: application/json

المفتاح العام

يحدّد مساحة العمل الخاصة بك. البادئة: pk_. آمن للتسجيل.

المفتاح السري

يُوقّع الطلبات. البادئة: sk_. يُعرض مرة واحدة فقط — احفظه في مدير أسرار.

يمكن حصر مفاتيح API في قدرات محددة وربطها اختيارياً بجلسة واتساب واحدة. الطلبات بدون القدرة المطلوبة تتلقى HTTP 403 insufficient_ability.

القدرات (النطاقات)

الصلاحية تمنح الوصول إلى
* Full access to all endpoints (wildcard).
sessions.read List and inspect connected sessions and bots.
messages.send POST /api/v1/messages/send.
messages.read GET /api/v1/messages and GET /api/v1/web-chat/messages.
contacts.read List and view contacts, groups, and tags.
contacts.write Create and update contacts, groups, and tags.
campaigns.read List and view campaigns and their stats. Older keys also read templates, automations and analytics with it.
campaigns.write Create, update, start, pause, resume, cancel and delete campaigns. Older keys also manage templates and automations with it.
templates.read List, show and preview message templates.
templates.write Create, update and delete message templates.
automations.read List and show automations (auto-replies).
automations.write Create, update, toggle and delete automations.
analytics.read GET /api/v1/analytics/* reports.
webhooks.read List and view webhooks and delivery logs.
webhooks.write Create, update, delete and test webhooks.
push.read GET /api/v1/push/broadcasts/{id} (delivery status and counts).
push.write POST /api/v1/push/broadcasts. Keys with campaigns.write can also send push broadcasts, so existing keys keep working.

حدود المعدل والحصص

كل مفتاح API لديه ثلاثة حدود مستقلة. يمكن تكوين تجاوزات لكل مفتاح عند إنشاء المفتاح — وإلا فإن الافتراضات العامة للمستأجر أدناه تنطبق. لكل مساحة عمل أيضًا حدود تحددها خطتها وتشترك فيها جميع مفاتيحها: 120 طلبًا في الدقيقة في الخطط التي تتضمن الـ API (و300 في خطط Business و600 في خطط Enterprise)، وحصة الطلبات اليومية للخطة، التي تُعاد عند منتصف الليل بتوقيت UTC وتعيد 429 plan_daily_quota_exceeded عند نفادها. ويُطبق الحد الأقل.

النطاق الافتراضي عند التجاوز
Per-minute burst
120 req / min
429 rate_limit_exceeded
Daily quota
10 000 req / day
429 daily_quota_exceeded
Monthly quota
250 000 req / mo
429 monthly_quota_exceeded

رؤوس الاستجابة

كل استجابة مصادقة تتضمن رؤوس تعرض استخدام الحصة الحالية. عند إرجاع 429، Retry-After يشير الرأس إلى عدد الثواني التي يجب الانتظارها.

الرأس (Header) المعنى
X-RateLimit-Limit Per-minute request ceiling for this key.
X-RateLimit-Daily-Limit Daily request quota for this key.
X-RateLimit-Daily-Remaining Requests still available today.
Retry-After Seconds to wait before retrying (only on 429 responses).

عدم التكرار

أعد محاولة الطلبات المعدِّلة بأمان دون خوف من إنشاء نسخ مكررة. أرفق الترويسة Idempotency-Key بطلب الإنشاء — إذا وصل المفتاح نفسه مرة أخرى خلال 24 ساعة على نقطة النهاية نفسها، يُعاد رمز الحالة الأصلي ونص الاستجابة كما هما تمامًا.

bash
curl -X POST https://zagely.com/api/v1/messages/send \
        -H "X-Public-Key: pk_your_public_key" \
        -H "X-Secret-Key: sk_your_secret_key" \
        -H "Idempotency-Key: 5b2f9e3c-7b8d-4a1e-9f1b-12ab34cd56ef" \
        -H "Content-Type: application/json" \
        -d '{"channel":"whatsapp","to":"+15551234567","message":"hi"}'
القاعدة القيمة
Applies to POST /api/v1/messages/send, /api/v1/contacts, /api/v1/contact-groups, /api/v1/campaigns, /api/v1/campaigns/{id}/start, /api/v1/webhooks and /api/v1/push/broadcasts. Other endpoints ignore the header.
Character set A–Z, a–z, 0–9, hyphen and underscore. Max 255 chars.
TTL 24 hours from the first accepted response.
Scope Per API key + request path. Different keys see different results.
Replay marker Replies add Idempotent-Replay: true header.
Same key, different body 422 idempotency_key_reused. The key is stored with a fingerprint of the request body; JSON key order and whitespace do not count as a difference. Use a new key for every new request.
Malformed key 400 invalid_idempotency_key.
Duplicate while running 409 idempotency_in_progress with Retry-After: 1 while the first request with the key is still executing. Retry to receive its stored response.
Not stored Error responses (4xx/5xx) are not stored, so you can fix the problem — e.g. top up after 402 insufficient_balance — and retry with the same key.

نقاط النهاية العامة

نقاط نهاية مساعدة لمراقبة مفتاح API الخاص بك وفحصه.

GET
/api/v1/health
عام

فحص توفر بدون مصادقة. يعيد 200 عندما تكون قاعدة البيانات متاحة، و503 في غير ذلك.

json
{ "data": { "status": "ok", "timestamp": "2026-04-22T12:00:00Z" } }
GET
/api/v1/me

تعيد مفتاح API الحالي مع صلاحياته، والجلسة المرتبطة به، وحدوده الخاصة، وعدادات الاستخدام لليوم ولهذا الشهر، ورصيد زاجلز في مساحة العمل. تكون zagels.available بقيمة null وzagels.unlimited بقيمة true في الخطط غير المحدودة. يُطلق balance.low عندما ينخفض الرصيد عن zagels.low_balance_threshold. تُظهر plan.features الميزات التي تتضمنها خطتك، وتُظهر plan.api_limits حدود الطلبات في الدقيقة واليوم المشتركة بين جميع مفاتيح مساحة العمل (وتكون plan بقيمة null بدون اشتراك نشط)، حتى تتحقق من المفتاح قبل الاعتماد عليه.

json
{
            "data": {
            "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
            "name": "Production Key",
            "tenant_id": "...",
            "session_id": null,
            "abilities": ["messages.send", "contacts.read"],
            "expires_at": null,
            "last_used_at": "2026-04-22T11:59:02Z",
            "usage": { "today": 142, "month": 3_812 },
            "limits": { "daily": 10000, "monthly": 250000, "per_minute": 120 },
            "remaining": { "daily": 9858 },
            "zagels": { "available": 1250, "unlimited": false, "low_balance_threshold": 50 },
            "plan": {
            "name": "Growth",
            "features": { "whatsapp": true, "telegram": false, "messenger": false, "instagram": false, "email": true, "web_push": true, "ai": true, "api": true },
            "api_limits": { "per_minute": 120, "daily": 5000 }
            }
            }
            }

نظرة عامة على القنوات

كل طلب API ينشئ رسالة أو يرسلها يتطلب الحقل channel الذي يحدد للمنصة قناة المراسلة المستخدمة. ولكل قناة أيضًا مفهوم "اتصال" خاص بها يُشار إليه بالحقل session_id.

قيمة channel يشير session_id إلى هل session_id مطلوب؟ حقل المستلم
whatsapp WhatsApp session UUID
نعم
to (phone number)
whatsapp-official WhatsApp (Official) number UUID
نعم
to (phone number)
telegram Telegram bot UUID
نعم
contact_id or telegram_chat_id
messenger Messenger page UUID
نعم
contact_id (has messenger_psid)
instagram Instagram account UUID
نعم
contact_id (has instagram_igsid)
webpush Push subscriber UUID
نعم
contact_id (subscribed)
email — (not applicable)
لا
contact_id (has email)

لواتساب، استخدم whatsapp لجلسات واتساب ويب و whatsapp-official للأرقام على WhatsApp Cloud API. تحتاج الأرقام الرسمية إلى قالب معتمد كلما بدأت أنت المحادثة — راجع "الانتقال إلى WhatsApp Cloud API" في قسم الرسائل.

غير متاحة للتكاملات الجديدة: viber, discord. السجلات الحالية التي تستخدم هذه القنوات تظل قابلة للقراءة.

الرسائل

POST
/api/v1/messages/send

أرسل رسالة عبر القناة المحددة. توضع الرسالة في قائمة الانتظار وتُرسل بشكل غير متزامن — ويعيد الـ API معرّف الرسالة فورًا.

قبل وضع الرسالة في قائمة الانتظار، يتحقق الـ API من كل ما يمكن التحقق منه مسبقًا — الجلسة والمستلم والقالب ورصيد زاجلز — ويرفض الطلب برمز خطأ إذا كانت الرسالة لن تنجح. الاستجابة 201 تعني أن الرسالة في قائمة الانتظار، وتصل نتيجتها النهائية عبر ويب هوك من نوع message.sent أو message.failed.

الحقل النوع مطلوب الوصف
channel string
مطلوب
Messaging channel to use: whatsapp (legacy WhatsApp Web session) or whatsapp-official (WhatsApp Cloud API number). See Channels Overview for the full list.
to string
مطلوب
Recipient phone number (E.164: +15551234567). Auto-normalised — spaces and dashes stripped.
message string
اختياري
Text body. Required when type is text (default). Omit for media-only and template messages. For image, video and document messages on whatsapp and whatsapp-official it is the caption, limited to 1024 characters (longer captions return 422 validation_failed).
type string
اختياري
Message type: text (default), image, video, audio, document, template. template is only available on whatsapp-official.
session_id uuid
اختياري
WhatsApp session UUID, or WhatsApp (Official) number UUID for whatsapp-official. Optional only when the API key is bound to a WhatsApp session — always send it for whatsapp-official.
media_url string
اختياري
Publicly accessible URL of the media file. Required when type is image, video, audio or document. On the whatsapp channel, transparent PNG images are placed on a white background before sending, because WhatsApp would otherwise show the transparent areas as black.
template.name string
اختياري
Approved template name. Required when type is template.
template.language string
اختياري
Template language code exactly as approved, e.g. en_US or ar. Required when type is template.
variables string[]
اختياري
Values for the template body placeholders, in order (first value fills placeholder 1, and so on). The count must match the template.
reference string
اختياري
Your own identifier for this message (max 255 chars). Returned in the response and echoed in every message.* webhook.
metadata object
اختياري
Any JSON object (max 4 KB encoded). Returned in the response and echoed in every message.* webhook.
contact_name string
اختياري
Name for the recipient contact. Applied when the contact is new or still named after its phone number; never overwrites a name you set.

أرسل رسالة نصية

bash
curl -X POST https://zagely.com/api/v1/messages/send \
            -H "X-Public-Key: pk_your_public_key" \
            -H "X-Secret-Key: sk_your_secret_key" \
            -H "Content-Type: application/json" \
            -d '{
            "channel": "whatsapp",
            "session_id": "11111111-2222-3333-4444-555555555555",
            "to": "+15551234567",
            "message": "Hello from Zagely! 👋"
            }'

أرسل صورة

bash
curl -X POST https://zagely.com/api/v1/messages/send \
                -H "X-Public-Key: pk_your_public_key" \
                -H "X-Secret-Key: sk_your_secret_key" \
                -H "Content-Type: application/json" \
                -d '{
                "channel": "whatsapp",
                "session_id": "11111111-2222-3333-4444-555555555555",
                "to": "+15551234567",
                "type": "image",
                "media_url": "https://example.com/promo.jpg",
                "message": "Check out our latest offer!"
                }'

إرسال قالب معتمد (whatsapp-official)

bash
curl -X POST https://zagely.com/api/v1/messages/send \
                    -H "X-Public-Key: pk_your_public_key" \
                    -H "X-Secret-Key: sk_your_secret_key" \
                    -H "Idempotency-Key: notif-8812" \
                    -H "Content-Type: application/json" \
                    -d '{
                    "channel": "whatsapp-official",
                    "session_id": "66666666-7777-8888-9999-000000000000",
                    "to": "+15551234567",
                    "type": "template",
                    "template": { "name": "invoice_ready", "language": "en_US" },
                    "variables": ["Mona", "INV-42"],
                    "reference": "notif_8812",
                    "metadata": { "invoice_id": 42 },
                    "contact_name": "Mona Adel"
                    }'

استجابة 201

json
{
                    "status": "queued",
                    "message_id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
                    "reference": "notif_8812",
                    "metadata": { "invoice_id": 42 }
                    }

تكون قيمة reference وmetadata هي null عندما لا ترسلهما.

أخطاء الإرسال

تُعاد هذه الأخطاء بشكل متزامن، فلا يوضع شيء في قائمة الانتظار ولا تُخصم أي زاجلز. كل خطأ يستخدم الغلاف القياسي الموضح في قسم الأخطاء.

error.code الحالة متى
insufficient_balance 402 Your Zagel balance is empty. details.available and details.required show the numbers. Top up, then retry with the same Idempotency-Key.
session_required 422 No session_id in the body and the API key is not bound to a session.
session_not_found 404 The session does not exist or belongs to another workspace.
session_not_connected 422 The session is disconnected or inactive. details.status holds its current status.
invalid_recipient 422 The to field does not contain a usable phone number.
template_not_supported 422 type is template on a channel other than whatsapp-official, or the template needs header, media or button parameters.
template_not_found 422 No template with that name and language is synced for the number. Sync templates in the dashboard first.
template_not_approved 422 The template exists but Meta has not approved it. details.status holds its status.
template_variables_mismatch 422 The number of variables does not match the template. See details.expected and details.received.
outside_customer_service_window 422 Free-form message on whatsapp-official to a contact who has not written to the number in the last 24 hours. Send a template instead.

بعض حالات الفشل لا تحدث إلا بعد وضع الرسالة في قائمة الانتظار — كأن تنقطع الجلسة، أو يرفض واتساب المستلم، أو ينفد الرصيد في أثناء ذلك. وتصل هذه الحالات عبر ويب هوك من نوع message.failed يحمل error_message وto وقيمة reference الخاصة بك.

الانتقال إلى WhatsApp Cloud API

ينتقل واتساب على Zagely من جلسات واتساب ويب (القناة whatsapp) إلى الأرقام الرسمية على WhatsApp Cloud API من Meta (القناة whatsapp-official). تستمر جلسات whatsapp الحالية في العمل بالنص الحر. القواعد التالية تنطبق على أرقام whatsapp-official فقط.

الحالة whatsapp whatsapp-official
You start the conversation (notifications, reminders, OTPs) Free text Approved template required
Contact wrote to you within the last 24 hours Free text Free text, media or template
Zagels per message 1 5
API key can be bound to the session Yes No — send session_id in every request

قائمة خطوات الانتقال

  1. اربط رقمًا رسميًا من WhatsApp (الرسمي) في الشريط الجانبي وانسخ معرّفه — فهو قيمة session_id الجديدة.
  2. أنشئ قالبًا في WhatsApp Manager لكل إشعار تبدأ أنت بإرساله (فئة Utility للرسائل التشغيلية)، وانتظر موافقة Meta، ثم زامن القوالب من لوحة التحكم.
  3. غيّر عمليات الإرسال هذه إلى القناة whatsapp-official مع type بقيمة template، وtemplate.name، وtemplate.language، وقيمة واحدة في variables لكل متغير في نص القالب.
  4. استخدم الإرسال بالنص الحر فقط للرد على جهات الاتصال التي راسلتك خلال آخر 24 ساعة، وإلا ستحصل على 422 outside_customer_service_window.
  5. اشترك في الويب هوك من نوع message.failed وbalance.low، وتحقق من zagels.available في GET /api/v1/me، حتى تلاحظ المشكلات قبل مستخدميك.

القوالب التي تحتوي على متغيرات في الترويسة، أو ترويسات وسائط، أو روابط أزرار ديناميكية، أو متغيرات مسماة لا يمكن إرسالها عبر الـ API بعد، وتُرفض بالرمز template_not_supported.

GET
/api/v1/messages

تعيد قائمة رسائل مقسمة إلى صفحات (50 لكل صفحة). جميع معاملات الاستعلام اختيارية.

معامل الاستعلام الوصف
channel Filter by channel: whatsapp, telegram, messenger, etc.
session_id Filter by session UUID.
contact_id Filter by contact UUID.
direction inbound or outbound.
json
// 200 Response — paginated list
                {
                "current_page": 1,
                "data": [
                {
                "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
                "channel": "whatsapp",
                "direction": "inbound",
                "type": "text",
                "content": "Hi, I need help!",
                "status": "received",
                "created_at": "2026-04-21T10:00:00Z",
                "contact": { "id": "...", "name": "Jane Doe", "phone_number": "+15551234567" },
                "session": { "id": "...", "name": "My Store Session" }
                }
                ],
                "per_page": 50,
                "total": 1204
                }
GET
/api/v1/web-chat/messages

تعيد رسائل أداة دردشة واحدة على موقعك، الأحدث أولًا، 50 لكل صفحة. تحتاج إلى الصلاحية messages.read. مرّر رمز الأداة في معامل الاستعلام widget_token، وتعيد أداة تابعة لمساحة عمل أخرى 404 widget_not_found.

bash
curl "https://zagely.com/api/v1/web-chat/messages?widget_token=22222222-3333-4444-5555-666666666666" \
                -H "X-Public-Key: pk_your_public_key" \
                -H "X-Secret-Key: sk_your_secret_key"

الجلسات والبوتات

نقاط النهاية تحت ‎/api/v1 فقط تقبل مفاتيح API. أما نقاط النهاية تحت ‎/api/‎ بدون ‎/v1 فتستخدمها لوحة تحكم Zagely وتحتاج إلى جلسة دخول إلى لوحة التحكم، لذا لا يستطيع تطبيقك استدعاءها.

تتطلب كل قناة "جلسة" متصلة قبل إرسال الرسائل. ويختلف هذا المفهوم من قناة لأخرى:

القناة نوع الاتصال تُدار عبر
whatsapp WhatsApp Session (QR scan) API (below) or Dashboard
telegram Telegram Bot (bot token) Dashboard → Channels → Telegram
messenger Messenger Page (Meta OAuth) Dashboard → Channels → Messenger
instagram Instagram Account (Meta OAuth) Dashboard → Channels → Instagram
webpush Push Site Key (VAPID) Dashboard → Channels → Web Push
email Tenant SMTP config Dashboard → Settings → Email

API جلسات واتساب

GET
/api/v1/sessions

تعيد جميع جلسات واتساب في مساحة عملك مع حالتها الحالية.

json
// 200 Response
            {
            "current_page": 1,
            "data": [
            {
            "id": "11111111-2222-3333-4444-555555555555",
            "name": "Customer Support",
            "phone_number": "+15551234567",
            "status": "connected",
            "daily_limit": 500,
            "warmup_enabled": true,
            "created_at": "2026-01-10T08:00:00Z"
            }
            ],
            "total": 3
            }
GET
/api/v1/sessions/{session}

تجلب الحالة الحالية لجلسة واحدة. الحالات الممكنة: connecting وconnected وdisconnected وbanned.

POST
/api/whatsapp/sessions
لوحة التحكم فقط

تنشئ جلسة واتساب جديدة وتبدأ عملية الربط برمز QR.

الحقل مطلوب الوصف
name
مطلوب
Human-readable label for the session (max 255).
phone_number
اختياري
Expected phone number (informational; set automatically on QR scan).
json
// 201 Response
            {
            "id": "11111111-2222-3333-4444-555555555555",
            "name": "Customer Support",
            "status": "connecting",
            "qr_code": "data:image/png;base64,iVBOR..."
            }
PUT
/api/whatsapp/sessions/{session}
لوحة التحكم فقط

تحدّث إعدادات الجلسة. جميع الحقول اختيارية — تتغير الحقول المرسلة فقط.

الحقل النوع الوصف
name string Human-readable label.
description string Optional description.
daily_limit integer Max messages per day (min 1).
warmup_enabled boolean Enable gradual send ramp-up.
warmup_start_limit integer Messages per day at warmup start.
warmup_max_limit integer Messages per day at warmup peak.
warmup_days integer Days to reach peak limit.
simulate_typing boolean Add realistic typing delay before each message.
الطريقة المسار الوصف
GET
/api/whatsapp/sessions/{session}/qr Current QR code image (base64). Poll while status = connecting.
POST
/api/whatsapp/sessions/{session}/disconnect Gracefully disconnect. Status → disconnected.
DELETE
/api/whatsapp/sessions/{session} Disconnect and permanently delete the session.

جهات الاتصال

نقاط النهاية تحت ‎/api/v1 فقط تقبل مفاتيح API. أما نقاط النهاية تحت ‎/api/‎ بدون ‎/v1 فتستخدمها لوحة تحكم Zagely وتحتاج إلى جلسة دخول إلى لوحة التحكم، لذا لا يستطيع تطبيقك استدعاءها.
GET
/api/v1/contacts

قائمة جهات اتصال مقسمة إلى صفحات وقابلة للتصفية. حجم الصفحة الافتراضي 50.

معامل الاستعلام الوصف
search Partial match on name, phone_number, or email.
tags Array — contacts that have ALL tags. e.g. ?tags[]=vip&tags[]=active.
is_blocked boolean — true returns only blocked contacts.
opted_out boolean — true returns opted-out contacts.
group_id UUID — contacts belonging to this contact group.
sort_by name, phone_number, email, created_at (default), updated_at.
sort_order asc or desc (default).
per_page Items per page 1–200. Default 50.
json
// 200 Response
            {
            "current_page": 1,
            "data": [
            {
            "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
            "name": "Jane Doe",
            "phone_number": "+15551234567",
            "email": "jane@example.com",
            "tags": ["vip", "active"],
            "is_blocked": false,
            "opted_out_at": null,
            "custom_fields": { "city": "New York" },
            "groups": [{ "id": "...", "name": "VIP Customers" }],
            "created_at": "2026-01-15T09:00:00Z"
            }
            ],
            "total": 842,
            "per_page": 50
            }
POST
/api/v1/contacts

تنشئ جهة اتصال جديدة. وتعيد 422 إذا كانت هناك جهة اتصال بنفس رقم الهاتف في مساحة عملك.

الحقل مطلوب الوصف
phone_number
مطلوب
E.164 recommended (+15551234567). Non-digit chars stripped automatically.
name
اختياري
Display name. Defaults to phone number if omitted.
email
اختياري
Valid email address.
tags
اختياري
String array: ["vip", "newsletter"].
notes
اختياري
Free-text notes.
custom_fields
اختياري
Key-value object: {"city": "NY", "plan": "gold"}.
bash
curl -X POST https://zagely.com/api/v1/contacts \
            -H "X-Public-Key: pk_your_public_key" \
            -H "X-Secret-Key: sk_your_secret_key" \
            -H "Content-Type: application/json" \
            -d '{
            "phone_number": "+15551234567",
            "name": "Jane Doe",
            "email": "jane@example.com",
            "tags": ["vip", "newsletter"],
            "custom_fields": { "city": "New York", "plan": "gold" }
            }'
الطريقة المسار الوصف
GET
/api/v1/contacts/{contact} Get a contact with last 10 messages and all groups.
PUT
/api/v1/contacts/{contact} Update fields. All fields optional — only sent fields change.
DELETE
/api/v1/contacts/{contact} Permanently delete contact and linked data.
POST
/api/v1/contacts/{contact}/block Block — contact stops receiving campaign messages (contacts.write).
POST
/api/v1/contacts/{contact}/unblock Unblock a previously blocked contact (contacts.write).
POST
/api/contacts/import Dashboard only. Bulk import from CSV/XLSX file (async). Returns 202.
POST
/api/contacts/export Dashboard only. Start async export with optional filters. Returns 202.

مجموعات جهات الاتصال

تُدار المجموعات الثابتة يدويًا، بينما تتحدث المجموعات الديناميكية تلقائيًا بناءً على المرشحات.

POST
/api/v1/contact-groups
الحقل مطلوب الوصف
name
مطلوب
Group label (max 255).
type
مطلوب
static — manually managed; dynamic — auto-filtered.
description
اختياري
Optional description.
filters
اختياري
Required when type is dynamic. Keys: tags (array), custom_fields (object), created_from, created_to.
json
// Static group
            { "name": "VIP Customers", "type": "static" }

            // Dynamic group
            {
            "name": "New VIPs",
            "type": "dynamic",
            "filters": { "tags": ["vip"], "created_from": "2026-01-01" }
            }
bash
curl -X POST https://zagely.com/api/v1/contact-groups \
            -H "X-Public-Key: pk_your_public_key" \
            -H "X-Secret-Key: sk_your_secret_key" \
            -H "Content-Type: application/json" \
            -d '{ "name": "VIP Customers", "type": "static" }'
bash
# Add contacts to a static group — by UUID or phone number
            curl -X POST https://zagely.com/api/v1/contact-groups/{group_id}/contacts \
            -H "X-Public-Key: pk_your_public_key" \
            -H "X-Secret-Key: sk_your_secret_key" \
            -H "Content-Type: application/json" \
            -d '{ "phone_numbers": ["+201140220996", "+201001234567"] }'
الطريقة المسار الوصف
GET
/api/v1/contact-groups List groups with contacts_count.
GET
/api/v1/contact-groups/{group} Show group and first 100 contacts.
PUT
/api/v1/contact-groups/{group} Update name, description, or filters.
DELETE
/api/v1/contact-groups/{group} Delete group (contacts are not deleted).
POST
/api/v1/contact-groups/{group}/contacts Add members to a static group. Body: contact_ids (UUIDs) and/or phone_numbers (strings).
DELETE
/api/v1/contact-groups/{group}/contacts Remove members from a static group. Body: contact_ids (UUIDs) and/or phone_numbers (strings).

العلامات

الوسوم تسميات حرة تُحفظ على جهات الاتصال. تتيح لك نقاط النهاية هذه عرض الوسوم أو إعادة تسميتها أو حذفها في جميع جهات الاتصال في مساحة عملك.

الطريقة المسار الوصف
GET
/api/v1/tags List all tags with contacts_count. Optional ?search= filter.
PUT
/api/v1/tags/{tag} Rename a tag across all contacts. Body: { "name": "new-tag" }.
DELETE
/api/v1/tags/{tag} Remove a tag from all contacts.
bash
# List tags
        curl https://zagely.com/api/v1/tags \
        -H "X-Public-Key: pk_your_public_key" \
        -H "X-Secret-Key: sk_your_secret_key"

        # Rename a tag
        curl -X PUT https://zagely.com/api/v1/tags/vip \
        -H "X-Public-Key: pk_your_public_key" \
        -H "X-Secret-Key: sk_your_secret_key" \
        -H "Content-Type: application/json" \
        -d '{ "name": "premium" }'

        # Delete a tag
        curl -X DELETE https://zagely.com/api/v1/tags/vip \
        -H "X-Public-Key: pk_your_public_key" \
        -H "X-Secret-Key: sk_your_secret_key"

القوالب

تحتاج إلى الصلاحية templates.read لعرض القوالب وقراءتها ومعاينتها، وإلى templates.write لإنشائها وتحديثها وحذفها. تستمر المفاتيح التي تملك campaigns.read أو campaigns.write في العمل.

قوالب رسائل قابلة لإعادة الاستخدام مع استبدال المتغيرات. استخدم {{name}}, {{phone}}, أو مفتاح أي حقل مخصص.

POST
/api/v1/templates
الحقل مطلوب الوصف
name
مطلوب
Unique template name within your workspace.
channel
مطلوب
whatsapp, telegram, messenger, webpush, email, or all.
content
مطلوب
Message body. Use {{variable}} placeholders for dynamic values.
media_url
اختياري
Attach media to the template.
buttons
اختياري
Array of quick-reply or CTA button objects.
variables
اختياري
Array of variable names. Auto-extracted from {{...}} in content if omitted.
json
{
            "name": "Order Confirmation",
            "channel": "whatsapp",
            "content": "Hi {{ name }}! Your order #{{ order_id }} is confirmed.
            We ship by {{ ship_date }}. 🎉"
            }

استجابة 201

json
{
                "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
                "name": "Order Confirmation",
                "channel": "whatsapp",
                "variables": ["name", "order_id", "ship_date"],
                "created_at": "2026-04-21T12:00:00Z"
                }
POST
/api/v1/templates/{template}/preview

اعرض القالب بقيم حقيقية. مرّر contact_id (يملأ حقول جهة الاتصال تلقائيًا) أو كائن variables.

json
// By contact
            { "contact_id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" }

            // By values
            { "variables": { "name": "Jane", "order_id": "ORD-001", "ship_date": "April 25" } }
GET
/api/v1/templates List templates (templates.read). Filters: search, channel. Paginated, per_page up to 100.
GET
/api/v1/templates/{template} Get one template (templates.read).
PUT
/api/v1/templates/{template} Update name, channel, content, media_url, buttons or variables (templates.write). Variables are re-extracted when content changes without variables.
DELETE
/api/v1/templates/{template} Delete the template (templates.write).

الحملات الإعلانية

الإجراء الذي لا تسمح به الحالة الحالية يعيد 422 invalid_campaign_status، ويذكر error.details الحالة الحالية والحالات التي تسمح به.

تسمح كل خطة بعدد من الحملات الجديدة في كل شهر ميلادي. إنشاء حملة بعد بلوغه يعيد 403 plan_campaign_limit_reached، لذا أعد استخدام الحملة بدلًا من إنشاء حملة لكل رسالة.

POST
/api/v1/campaigns

تنشئ حملة بحالة مسودة. ابدأها بشكل منفصل عبر نقطة النهاية ‎/start. لا يمكن تعديل الحملة بعد بدء تشغيلها.

الحقل مطلوب الوصف
name
مطلوب
Campaign name (max 255).
channel
اختياري
Sending channel. Default: whatsapp. Values: whatsapp, telegram, messenger, webpush, email.
session_id
اختياري
UUID of the channel session/bot to use. Required for all channels except email.
message_content
مطلوب
Message body sent to each recipient.
target_type
مطلوب
all — every contact; group — a contact group; filter — custom filters.
media_url
اختياري
Attach a media file to the message.
buttons
اختياري
Array of quick-reply button objects.
target_filters
اختياري
Required when target_type is group or filter. Object with group_id, tags, etc.
scheduled_at
اختياري
ISO 8601 datetime in the future. Campaign launches automatically at this time.
bash
curl -X POST https://zagely.com/api/v1/campaigns \
            -H "X-Public-Key: pk_your_public_key" \
            -H "X-Secret-Key: sk_your_secret_key" \
            -H "Content-Type: application/json" \
            -d '{
            "name": "April Flash Sale",
            "channel": "whatsapp",
            "session_id": "11111111-2222-3333-4444-555555555555",
            "message_content": "Hi {{ name }}! Flash sale — 30% off today only. Shop
            now 👉 https://example.com/sale",
            "target_type": "group",
            "target_filters": { "group_id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" },
            "scheduled_at": "2026-04-25T09:00:00Z"
            }'
GET
/api/v1/campaigns/{campaign}/stats
json
{
            "total_recipients": 1500,
            "sent_count": 1450,
            "delivered_count": 1380,
            "read_count": 920,
            "failed_count": 50,
            "pending_count": 0,
            "delivery_rate": 95.17,
            "read_rate": 66.67
            }

نقاط نهاية دورة الحياة

GET
/api/v1/campaigns List campaigns (campaigns.read).
GET
/api/v1/campaigns/{campaign} Get one campaign (campaigns.read).
POST
/api/v1/campaigns/{campaign}/start draft, scheduled, paused → running (campaigns.write).
GET
/api/v1/campaigns/{campaign}/stats Delivery counts and rates (campaigns.read).
POST
/api/v1/campaigns/{campaign}/pause running → paused (campaigns.write).
POST
/api/v1/campaigns/{campaign}/resume paused or canceled → running (campaigns.write).
POST
/api/v1/campaigns/{campaign}/cancel scheduled, running, paused → canceled (campaigns.write).
PUT
/api/v1/campaigns/{campaign} Update — draft or scheduled only (campaigns.write).
DELETE
/api/v1/campaigns/{campaign} Delete — not while running or completed (campaigns.write).

الأتمتة

تحتاج إلى الصلاحية automations.read لعرض الأتمتة وقراءتها، وإلى automations.write لإنشائها وتعديلها وتشغيلها أو إيقافها وحذفها. تستمر المفاتيح التي تملك campaigns.read أو campaigns.write في العمل.

ردود تلقائية تعمل عند تحقق شرط معين. أنواع المشغّلات: keyword وwelcome وaway وfallback.

POST
/api/v1/automations
الحقل مطلوب الوصف
session_id
مطلوب
WhatsApp session (or bot) this automation listens on.
name
مطلوب
Automation label (max 255).
channel
اختياري
Channel scope. Default: whatsapp. Values: whatsapp, telegram, messenger, webpush, email, all.
trigger_type
مطلوب
keyword, welcome (first contact), away (outside hours), fallback (no match).
trigger_value
اختياري
Keyword to match. Required when trigger_type is keyword.
response_content
مطلوب
Message body to send as the automatic reply.
response_media_url
اختياري
Media attachment for the response.
response_buttons
اختياري
Array of quick-reply buttons.
conditions
اختياري
Extra conditions object.
priority
اختياري
Integer 0–100. Higher priority evaluated first. Default 0.
json
{
            "session_id": "11111111-2222-3333-4444-555555555555",
            "name": "Price Enquiry Reply",
            "channel": "whatsapp",
            "trigger_type": "keyword",
            "trigger_value": "price",
            "response_content": "Hi {{ name }}! Our plans start at $29/month. Visit
            https://example.com/pricing for details.",
            "priority": 10
            }
الطريقة المسار الوصف
GET
/api/v1/automations List automations (automations.read). Filter: session_id, is_active, trigger_type. Paginated, per_page up to 100.
GET
/api/v1/automations/{automation} Show automation with last 50 trigger logs (automations.read).
PUT
/api/v1/automations/{automation} Update any field (automations.write).
DELETE
/api/v1/automations/{automation} Delete automation (automations.write).
POST
/api/v1/automations/{automation}/toggle Toggle is_active on/off (automations.write).

التحليلات

نقاط نهاية للقراءة فقط تحتاج إلى الصلاحية analytics.read (وتستمر المفاتيح التي تملك campaigns.read في العمل). يستخدم from_date وto_date الصيغة YYYY-MM-DD، ويشمل to_date يومه كاملًا.

GET
/api/v1/analytics/overview

High-level snapshot: total contacts, active sessions, campaigns this month, messages today. No parameters.

json
{"total_contacts":4821,"active_sessions":3,"campaigns_this_month":12,"messages_today":347}
GET
/api/v1/analytics/campaigns

Campaign delivery summary. Optional: from_date, to_date.

json
{"summary":{"total_campaigns":12,"total_sent":14800,"avg_delivery_rate":95.94},"campaigns":[...]}
GET
/api/v1/analytics/sessions

Session message stats. Optional: from_date, to_date.

json
{"summary":{"total_sessions":3,"active_sessions":2,"total_messages_sent":8430},"sessions":[...]}
GET
/api/v1/analytics/contacts

Contact growth data. Optional: from_date, to_date (defaults to last 30 days).

json
{"stats":{"total_contacts":4821,"new_contacts":342},"growth_data":[{"date":"2026-04-21","count":15}]}
GET
/api/v1/analytics/message-activity

Hourly message volume by direction. Optional: from_date, to_date (defaults to last 7 days).

json
[{"date":"2026-04-21","hour":9,"direction":"outbound","count":124}]

إشعارات الويب

أرسل إشعار متصفح إلى مشتركي الإشعارات في موقعك من الكود الخاص بك، مثلًا عند نشر مقال جديد. يجب أن تتضمن خطتك إشعارات الويب، وإلا يعيد الـ API الرمز 403 feature_not_available مع details.feature بقيمة "web_push".

الطريقة المسار الصلاحية الوصف
POST
/api/v1/push/broadcasts push.write (or campaigns.write) Queue a broadcast to all active subscribers, or to one language.
GET
/api/v1/push/broadcasts/{id} push.read, push.write or campaigns.read Get a broadcast's status and its delivered, failed and clicked counts.

إرسال بث

الحقل النوع الوصف
title string, required Notification title. Max 200 characters.
body string, required Notification text. Max 500 characters.
url URL, optional Page opened when the notification is clicked. Defaults to your site root.
icon URL, optional Small icon. Defaults to the push icon set in your dashboard.
image URL, optional Large image shown in the notification (supported by Chrome and Edge).
audience.lang string, optional Only send to subscribers whose browser language starts with this code, e.g. "ar" matches ar and ar-EG. Omit to send to everyone.
bash
curl -X POST https://zagely.com/api/v1/push/broadcasts \
        -H "X-Public-Key: pk_your_public_key" \
        -H "X-Secret-Key: sk_your_secret_key" \
        -H "Idempotency-Key: article-1842" \
        -H "Content-Type: application/json" \
        -d '{
        "title": "New article: Laravel tips",
        "body": "Five tips to speed up your app.",
        "url": "https://example.com/blog/laravel-tips",
        "image": "https://example.com/covers/laravel-tips.jpg",
        "audience": { "lang": "en" }
        }'

يعيد البث الموضوع في قائمة الانتظار 202. وعندما لا يطابق أي مشترك، لا يُرسل شيء وتكون الاستجابة 200 مع status بقيمة "skipped". لإرسال الخبر نفسه بلغتين، أرسل بثًا لكل لغة، لكل منهما Idempotency-Key خاص به.

json
// 202 Accepted
        { "status": "queued", "broadcast_id": "9c1d2e3f-...", "recipient_count": 1240 }

        // 200 OK — nobody to send to
        { "status": "skipped", "recipient_count": 0, "message": "No active push subscribers for this language." }

التحقق من التسليم

تكون قيمة status إما queued أو sent أو failed. تُملأ الأعداد عند انتهاء الإرسال، ويستمر clicked_count في الزيادة مع نقرات المستخدمين. يشمل failed_count الاشتراكات التي أنهاها المتصفح، والتي تُعطَّل تلقائيًا. لتُبلَّغ بانتهاء الإرسال بدلًا من الاستعلام المتكرر، اشترك بويب هوك في push.broadcast.sent وpush.broadcast.failed.

json
{
        "data": {
        "id": "9c1d2e3f-...",
        "status": "sent",
        "title": "New article: Laravel tips",
        "body": "Five tips to speed up your app.",
        "url": "https://example.com/blog/laravel-tips",
        "audience": { "lang": "en" },
        "recipient_count": 1240,
        "delivered_count": 1198,
        "failed_count": 42,
        "clicked_count": 87,
        "error_message": null,
        "created_at": "2026-11-03T09:00:00+00:00",
        "sent_at": "2026-11-03T09:00:41+00:00"
        }
        }

لغة المشترك

تُسجَّل اللغة التي يستخدمها audience.lang عند اشتراك الزائر. يرسل سكربت طلب الاشتراك اللغة التي تحددها عبر ‎?lang=‎ أو window.ZagelyPushConfig.lang (مع الرجوع إلى سمة lang في وسم html للصفحة). وإذا لم تُرسل لغة، تُستخدم ترويسة Accept-Language في المتصفح. المشتركون الذين انضموا قبل تسجيل اللغات تُسجل لهم لغة في المرة التالية التي يفتحون فيها صفحة تحمّل سكربت الاشتراك، وحتى ذلك الحين لا يصلهم البث الموجّه للغة.

الويب هوك

ترسل الويب هوك إشعارات الأحداث فورًا إلى خادمك كطلبات HTTP POST، دون حاجة إلى الاستعلام المتكرر.

إدارة الويب هوك عبر الـ API

الطريقة نقطة النهاية الغرض
GET
/api/v1/webhooks List all webhooks for the workspace.
POST
/api/v1/webhooks Register a new webhook. Secret auto-generated if omitted.
GET
/api/v1/webhooks/{id} Retrieve a single webhook.
PUT
/api/v1/webhooks/{id} Update URL, events list, or active state.
DELETE
/api/v1/webhooks/{id} Remove the webhook.
GET
/api/v1/webhooks/{id}/deliveries Paginated delivery log (status, signature, attempts, duration).
POST
/api/v1/webhooks/{id}/test Dispatch a synthetic webhook.test event to the configured URL.

ترويسات التسليم

الرأس (Header) القيمة
X-Zagely-Event Event name (e.g. message.received).
X-Zagely-Delivery Unique delivery UUID. Use it for idempotency on your side.
X-Zagely-Timestamp Unix seconds when the request was signed.
X-Zagely-Signature sha256=<hex> — HMAC-SHA256 of "{timestamp}.{body}".
Content-Type application/json.

التحقق من التوقيع

النص الموقَّع هو {timestamp}.{raw_body}. استخدم دائمًا مقارنة آمنة من هجمات التوقيت.

php
$timestamp = $_SERVER['HTTP_X_ZAGELY_TIMESTAMP'] ?? '';
            $signature = $_SERVER['HTTP_X_ZAGELY_SIGNATURE'] ?? '';
            $body = file_get_contents('php://input');

            $expected = 'sha256=' . hash_hmac('sha256', $timestamp . '.' . $body,
            'your_webhook_secret');

            if (! hash_equals($expected, $signature)) {
            http_response_code(401); exit;
            }

            $event = json_decode($body, true);
javascript
// Node.js / Express — use express.raw() to keep the exact body bytes
                app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
                const timestamp = req.headers['x-zagely-timestamp'];
                const signature = req.headers['x-zagely-signature'];
                const expected  = 'sha256=' + require('crypto')
                .createHmac('sha256', process.env.ZAGELY_WEBHOOK_SECRET)
                .update(timestamp + '.' + req.body.toString('utf8'))
                .digest('hex');

                if (!require('crypto').timingSafeEqual(Buffer.from(signature),
                Buffer.from(expected))) {
                return res.status(401).send('Invalid signature');
                }

                const event = JSON.parse(req.body.toString('utf8'));
                res.sendStatus(200);
                });

أنواع الأحداث

الحدث متى يتم التفعيل
message.received New inbound message on any connected channel.
message.sent Outbound message successfully dispatched.
message.delivered Channel confirms delivery to recipient device.
message.read Recipient reads the message (WhatsApp & Email).
message.failed Delivery failed after all retries. data.error_message explains why.
campaign.started Campaign begins processing recipients.
campaign.completed All recipients have been processed.
campaign.paused Running campaign is paused.
contact.created New contact record is created.
contact.updated Contact fields are updated.
contact.opted_out Contact unsubscribes from email or push.
session.connected Session connects successfully.
session.disconnected Session loses connection.
balance.low Zagel balance dropped below the low-balance threshold (default 50). Sent at most once per 24 hours.
push.broadcast.sent A web push broadcast finished sending. data has recipient_count, delivered_count and failed_count.
push.broadcast.failed A web push broadcast could not be sent. data.error_message explains why.
webhook.test Synthetic event triggered from the dashboard or the /test endpoint.

مثال للحمولة

json
{
            "event": "message.received",
            "tenant_id": "uuid-of-tenant",
            "delivery_id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
            "occurred_at": "2026-04-21T10:30:00Z",
            "data": {
            "contact": { "id": "...", "name": "Jane Doe", "phone_number": "+15551234567", "email":
            null },
            "channel": "whatsapp",
            "content": "Hello, I need help with my order."
            }
            }

أحداث الرسائل الصادرة

تشترك message.sent وmessage.delivered وmessage.read وmessage.failed في حمولة واحدة. تعيد reference وmetadata ما أرسلته إلى POST /api/v1/messages/send، لتطابق الحدث مع سجلك. ولا يُضبط error_message إلا في message.failed.

json
{
            "event": "message.failed",
            "tenant_id": "uuid-of-tenant",
            "delivery_id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
            "occurred_at": "2026-11-03T10:30:00Z",
            "data": {
            "id": "bbbbbbbb-cccc-dddd-eeee-ffffffffffff",
            "channel": "whatsapp",
            "direction": "outbound",
            "type": "text",
            "status": "failed",
            "source": "api",
            "error_message": "Insufficient Zagel balance",
            "to": "15551234567",
            "contact_id": "...",
            "conversation_id": null,
            "session_id": "...",
            "reference": "notif_8812",
            "metadata": { "invoice_id": 42 },
            "sent_at": null,
            "delivered_at": null,
            "read_at": null
            }
            }

حمولة balance.low

json
{
            "event": "balance.low",
            "tenant_id": "uuid-of-tenant",
            "delivery_id": "cccccccc-dddd-eeee-ffff-000000000000",
            "occurred_at": "2026-11-03T10:30:00Z",
            "data": { "available": 42, "threshold": 50 }
            }

سياسة إعادة المحاولة: أي استجابة غير 2xx (أو انتهاء المهلة بعد 10 ثوانٍ) تؤدي إلى إعادة المحاولة. جدول التأخير: 10 ثوانٍ، 60 ثانية، 5 دقائق، 30 دقيقة، ساعتان. بعد 5 محاولات فاشلة يُعلَّم التسليم بالفشل ويظهر في سجلات الويب هوك لإعادة إرساله يدويًا.

أمثلة التكامل

نقاط بداية جاهزة للنسخ واللصق. كل مثال يبقي مفتاحك السري على الخادم، ويرسل Idempotency-Key حتى لا تؤدي إعادة المحاولة إلى إرسال مكرر، ويفحص error.code عند الفشل. استبدل حقول المثال ببياناتك.

Laravel — إرسال رسالة واتساب

php
// config/services.php
'zagely' => [
    'public_key' => env('ZAGELY_PUBLIC_KEY'),
    'secret_key' => env('ZAGELY_SECRET_KEY'),
],

// Anywhere in your app, e.g. a job dispatched when an order is paid
use Illuminate\Support\Facades\Http;

$response = Http::withHeaders([
        'X-Public-Key' => config('services.zagely.public_key'),
        'X-Secret-Key' => config('services.zagely.secret_key'),
        'Idempotency-Key' => 'order-paid-'.$order->id,
    ])
    ->acceptJson()
    ->post('https://zagely.com/api/v1/messages/send', [
        'channel' => 'whatsapp',
        'to' => $order->customer_phone,
        'message' => "Thanks! We received your payment for order #{$order->number}.",
        'reference' => (string) $order->id,
    ]);

if ($response->failed()) {
    // Branch on error.code, never on the human-readable message.
    report(new RuntimeException($response->json('error.code').': '.$response->json('error.message')));
}

JavaScript (Node.js) — إشعار بمقال جديد

js
// Node.js 18+ (server side). Never put your secret key in browser code.
const response = await fetch('https://zagely.com/api/v1/push/broadcasts', {
  method: 'POST',
  headers: {
    'X-Public-Key': process.env.ZAGELY_PUBLIC_KEY,
    'X-Secret-Key': process.env.ZAGELY_SECRET_KEY,
    'Idempotency-Key': `article-${article.id}`,
    'Content-Type': 'application/json',
    'Accept': 'application/json',
  },
  body: JSON.stringify({
    title: article.title,
    body: article.summary,
    url: article.url,
    audience: { lang: article.language }, // optional
  }),
});

const result = await response.json();
if (!response.ok) {
  throw new Error(`${result.error.code}: ${result.error.message}`);
}
console.log(result.status, result.broadcast_id);

WordPress — إشعار بكل منشور جديد

php
// In your theme's functions.php or a small plugin.
// Add to wp-config.php:
//   define('ZAGELY_PUBLIC_KEY', 'pk_...');
//   define('ZAGELY_SECRET_KEY', 'sk_...');

// Send a web push to your subscribers when a post is first published.
add_action('transition_post_status', function ($newStatus, $oldStatus, $post) {
    if ($newStatus !== 'publish' || $oldStatus === 'publish' || $post->post_type !== 'post') {
        return;
    }

    wp_remote_post('https://zagely.com/api/v1/push/broadcasts', [
        'timeout' => 15,
        'headers' => [
            'X-Public-Key' => ZAGELY_PUBLIC_KEY,
            'X-Secret-Key' => ZAGELY_SECRET_KEY,
            'Idempotency-Key' => 'wp-post-' . $post->ID,
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
        'body' => wp_json_encode([
            'title' => get_the_title($post),
            'body' => wp_trim_words(wp_strip_all_tags($post->post_content), 25),
            'url' => get_permalink($post),
            'image' => get_the_post_thumbnail_url($post, 'large') ?: null,
        ]),
    ]);
}, 10, 3);

أنشئ مفتاحًا بالصلاحيات التي يحتاجها التكامل فقط: messages.send لمثال Laravel، وpush.write لمثالي JavaScript وWordPress. استخدم زر الاختبار في صفحة مفاتيح API للتحقق من صلاحيات المفتاح وميزات خطتك قبل الإطلاق.

وكلاء الذكاء الاصطناعي (MCP)

اربط وكيل البرمجة بالذكاء الاصطناعي الذي تستخدمه، مثل Claude Code أو Cursor أو VS Code، بخادم Zagely MCP. يستطيع الوكيل حينها البحث في هذا المرجع، والتحقق من مفتاح API الخاص بك، وإرسال رسالة اختبار أثناء كتابة التكامل، فيستخدم نقاط النهاية والحقول ورموز الأخطاء الحقيقية بدلًا من التخمين.

MCP
https://zagely.com/mcp

الأدوات

الأداة مفتاح API ما الذي تفعله
search_docs
غير مطلوب
Searches this reference and returns the best matching passages.
get_docs_section
غير مطلوب
Returns one whole section of this reference as Markdown.
check_api_key
مطلوب
Shows whether the configured key works: abilities, bound session, quotas, Zagel balance and plan features. Same data as GET /api/v1/me.
send_test_message
مطلوب
Sends one WhatsApp text message through POST /api/v1/messages/send. Only to the phone number of a member of your workspace, at most 10 per hour per key, 1 Zagel each.

اربط وكيلك

أدوات التوثيق لا تحتاج إلى بيانات اعتماد. لاستخدام أدوات الحساب، أضف مفتاح API الخاص بك في الترويستين X-Public-Key وX-Secret-Key، تمامًا كما في REST API.

Claude Code

bash
claude mcp add --transport http zagely https://zagely.com/mcp \
        --header "X-Public-Key: pk_your_public_key" \
        --header "X-Secret-Key: sk_your_secret_key"

Cursor (.cursor/mcp.json)

json
{
        "mcpServers": {
        "zagely": {
        "url": "https://zagely.com/mcp",
        "headers": {
        "X-Public-Key": "pk_your_public_key",
        "X-Secret-Key": "sk_your_secret_key"
        }
        }
        }
        }

VS Code (.vscode/mcp.json)

json
{
        "servers": {
        "zagely": {
        "type": "http",
        "url": "https://zagely.com/mcp",
        "headers": {
        "X-Public-Key": "pk_your_public_key",
        "X-Secret-Key": "sk_your_secret_key"
        }
        }
        }
        }
أنشئ مفتاح API منفصلًا لوكيل الذكاء الاصطناعي وامنحه الصلاحيات التي يحتاجها فقط. سيحتوي ملف الإعدادات حينها على مفتاح سري، لذا أبقه خارج نظام التحكم في الإصدارات.

الحدود

  • بدون مفتاح API: ‏60 طلبًا في الدقيقة لكل عنوان IP.
  • مع مفتاح API: ‏120 طلبًا في الدقيقة لكل مفتاح. يُحتسب كل طلب ضمن حصص المفتاح، ويُرفض المفتاح المعطل أو المنتهي أو المحظور تمامًا كما في REST API.

الأخطاء

الكل /api/v1/* تستخدم الاستجابات نفس غلاف JSON حتى يتمكن العملاء من معالجة الأخطاء بطريقة موحدة.

json
{
        "error": {
        "code": "machine_readable_snake_case",
        "message": "Human-readable description.",
        "details": { /* optional context */ }
        }
        }

مُهمل: كانت POST /api/v1/messages/send وGET /api/v1/web-chat/messages تعيدان error كنص عادي مع حقل message في المستوى الأعلى. وهما الآن تستخدمان الغلاف أعلاه. ما زالت نسخة من error.message تُعاد في حقل message بالمستوى الأعلى حتى تستمر العملاء القديمة في العمل، لكنها ستُزال في إصدار قادم — اقرأ error.code وerror.message بدلًا منها.

رموز حالة HTTP

الحالة المعنى السبب الشائع
200 OK Success. Standard success for GET and some POST.
201 Created Resource created. Successful POST that creates a resource.
202 Accepted Job queued. Async operations: import, export, send.
400 Bad Request Malformed request. Invalid JSON or malformed Idempotency-Key.
401 Unauthorized Auth failure. Missing, wrong, inactive, or expired API keys.
402 Payment Required Insufficient balance. Not enough Zagels to send the message. Top up and retry.
403 Forbidden Not allowed. API key lacks the required ability, your plan does not include the feature, or the workspace has no user account. Retrying will not help.
404 Not Found Resource not found. Wrong UUID or belongs to another workspace.
409 Conflict Request in progress. A request with the same Idempotency-Key is still running. Retry after Retry-After seconds.
422 Unprocessable Validation failed. Missing / invalid field, duplicate unique value, or an Idempotency-Key reused with a different body.
429 Too Many Requests Rate limit or quota exceeded. Back off. Inspect Retry-After.
500 Internal Error Server error. Contact support with the full response body.
503 Service Unavailable Dependency down. Database or upstream temporarily unreachable.

رموز الأخطاء

error.code الحالة الوصف
credentials_missing 401 No X-Public-Key / X-Secret-Key header pair was sent.
invalid_credentials 401 The public key does not match or the secret is wrong.
key_inactive 401 The key is disabled or past its expires_at.
unauthenticated 401 Session authentication failed (non key-auth endpoints).
insufficient_ability 403 Key lacks the required scope. details.required_ability contains the missing scope.
feature_not_available 403 Your plan does not include this feature. details.feature names it (for example "web_push"). Upgrade the plan; retrying will not help.
whatsapp_unavailable 403 WhatsApp is not yet enabled for this workspace.
workspace_suspended 403 The workspace that owns this key is suspended. Contact support; retrying will not help.
subscription_inactive 403 The workspace has no active subscription. Renew or start a plan in the dashboard; retrying will not help.
plan_excludes_api 403 The plan of the workspace does not include API access. Upgrade to a plan with API access; retrying will not help.
plan_daily_quota_exceeded 429 The workspace used the daily API requests its plan includes, across all its keys. Wait for the reset at midnight UTC (Retry-After) or upgrade the plan.
plan_campaign_limit_reached 403 The workspace created the campaigns its plan allows this month. error.details has limit, used and resets_at. Reuse an existing campaign, upgrade the plan, or wait for resets_at; retrying will not help.
invalid_campaign_status 422 The campaign action is not allowed in the current status. error.details has status and allowed_statuses.
campaign_cannot_start 422 The campaign session is not connected, the subscription is not active, or the monthly campaign limit of the plan is reached. error.details.reason is session_not_connected, subscription_inactive or campaign_limit_reached.
tenant_misconfigured 403 The workspace that owns this key has no user account. Sign in to the dashboard or contact support; retrying will not help. (Returned 503 before November 2026.)
forbidden 403 Authorization policy denied the request.
not_found 404 Resource does not exist or belongs to another workspace.
validation_failed 422 One or more fields failed validation. details.errors is the errors object.
invalid_idempotency_key 400 The Idempotency-Key header violates length or character rules.
idempotency_in_progress 409 Another request with this Idempotency-Key is still being processed. Retry shortly to receive its result.
idempotency_key_reused 422 This Idempotency-Key was already used with a different request body. Use a new key for a new request.
insufficient_balance 402 Not enough Zagels to send. details.available and details.required show the numbers.
session_required 422 No session_id in the body and none bound to the API key.
session_not_found 404 Session does not exist or belongs to another workspace.
session_not_connected 422 Session is disconnected or inactive. details.status has its status.
invalid_recipient 422 The to field does not contain a usable phone number.
template_not_supported 422 Templates are only available on whatsapp-official, and only with body variables.
template_not_found 422 Template name and language are not synced for this number.
template_not_approved 422 Template is not approved by Meta. details.status has its status.
template_variables_mismatch 422 Wrong number of variables. details.expected and details.received show the counts.
outside_customer_service_window 422 Free-form message on whatsapp-official more than 24 hours after the contact last wrote. Use a template.
widget_not_found 404 Web chat widget does not exist or belongs to another workspace.
server_error 500 Unexpected failure. details.correlation_id identifies the request for support.
rate_limit_exceeded 429 Per-minute burst limit hit.
daily_quota_exceeded 429 Today's request quota is exhausted.
monthly_quota_exceeded 429 This month's request quota is exhausted.
json
// 422 — validation_failed
        {
        "error": {
        "code": "validation_failed",
        "message": "The given data was invalid.",
        "details": { "errors": { "channel": ["The channel field is required."] } }
        }
        }

        // 403 — insufficient_ability
        {
        "error": {
        "code": "insufficient_ability",
        "message": "The API key does not have the required ability.",
        "details": { "required_ability": "messages.send" }
        }
        }

        // 429 — daily_quota_exceeded
        {
        "error": {
        "code": "daily_quota_exceeded",
        "message": "Daily request quota exceeded.",
        "details": { "limit": 10000 }
        }
        }

جاهز للتكامل؟

أنشئ زوج مفاتيح API الخاص بك وابدأ البناء اليوم.