مرجع الواجهة البرمجية

واجهة REST صغيرة عبر HTTPS. كل استجابة تستخدم غلافاً واحداً؛ والمال دائماً سلسلة من الوحدات الصغرى.

الرابط الأساسي:

https://<store-domain>/api/v1

المصادقة

أرسل مفتاحك في ترويسة x-api-key مع كل طلب. تُعرض المفاتيح مرة واحدة، وتُخزَّن مُجزّأة، وقابلة للإلغاء.

-H "x-api-key: $KEY"

النطاقات

يحمل المفتاح نطاقات؛ ونداء بلا النطاق المطلوب يعيد FORBIDDEN.

catalog:read
purchase
orders:read

نقاط النهاية

GET
/b2b/catalog
النطاق: catalog:read

اعرض المنتجات بأسعار شريحتك وتوفّرها.

مثال طلب

curl https://your-store.com/api/v1/b2b/catalog?perPage=100 \
  -H "x-api-key: $KEY"

مثال استجابة

{
  "ok": true,
  "data": [{
    "id": "019f56a9-…", "slug": "steam-5-us",
    "name": { "en": "Steam $5 — United States" },
    "type": "code", "listPrice": "545", "yourPrice": "501",
    "currency": "USD", "available": true, "maxPerOrder": 20
  }],
  "meta": { "page": 1, "perPage": 100, "total": 38 }
}
POST
/b2b/orders
النطاق: purchase

أنشئ طلباً (غير قابل للتكرار، مدفوع من المحفظة).

مثال طلب

curl -X POST https://your-store.com/api/v1/b2b/orders \
  -H "x-api-key: $KEY" \
  -H "x-idempotency-key: po-2026-07-12-0001" \
  -H "content-type: application/json" \
  -d '{
    "externalRef": "po-2026-07-12-0001",
    "items": [{ "productId": "019f56a9-…", "quantity": 2 }]
  }'

مثال استجابة

{ "ok": true, "data": {
  "orderId": "019f5728-…", "number": "KC-MRI0BS8W-026F",
  "status": "paid", "total": "1002"
} }
GET
/b2b/orders
النطاق: orders:read

اعرض طلباتك.

مثال طلب

curl https://your-store.com/api/v1/b2b/orders \
  -H "x-api-key: $KEY"
GET
/b2b/orders/{orderId}
النطاق: orders:read

اقرأ طلباً واحداً مع أكواده المُسلَّمة.

مثال طلب

curl https://your-store.com/api/v1/b2b/orders/019f5728-… \
  -H "x-api-key: $KEY"

مثال استجابة

{ "ok": true, "data": {
  "orderId": "019f5728-…", "status": "delivered",
  "externalRef": "po-2026-07-12-0001", "total": "1002",
  "lines": [{
    "product": { "slug": "steam-5-us" }, "quantity": 2,
    "units": [{ "unitIndex": 0, "status": "delivered", "code": "XXXX-YYYY-ZZZZ" }]
  }]
} }
GET
/b2b/orders/by-ref/{externalRef}
النطاق: orders:read

اقرأ طلباً بمرجعك الخاص externalRef.

مثال طلب

curl https://your-store.com/api/v1/b2b/orders/by-ref/po-2026-07-12-0001 \
  -H "x-api-key: $KEY"
GET
/b2b/wallet
النطاق: catalog:read

اقرأ رصيد محفظتك.

مثال طلب

curl https://your-store.com/api/v1/b2b/wallet \
  -H "x-api-key: $KEY"

مثال استجابة

{ "ok": true, "data": { "cash": "48998", "currency": "USD" } }

عدم التكرار

أرسل ترويسة Idempotency-Key مع POST /b2b/orders. إعادة المحاولة بنفس المفتاح تعيد النتيجة الأولى — لا يُنشأ الطلب مرتين. ومرّر externalRef الخاص بك للبحث عن الطلب لاحقاً بمرجعك.

الأخطاء

تُعيد الإخفاقات نفس الغلاف مع ok:false ورمز ثابت. جدير بالمعالجة:

UNAUTHORIZED

Missing or revoked token

FORBIDDEN

Token lacks the scope for this call

IDEMPOTENCY_KEY_REQUIRED

Money-moving POST without x-idempotency-key

IDEMPOTENCY_KEY_REUSED

Same key, different body

INSUFFICIENT_FUNDS

Wallet balance below the order total

OUT_OF_STOCK

Not enough units available right now

LIMIT_EXCEEDED

A product's per-user daily cap refused a line

RATE_LIMITED

Back off and retry (reuse the same idempotency key)