تقسيم الصفحات
تعيد كل نقاط النهاية التي تعرض قوائم الغلاف نفسه، حتى القوائم القصيرة مثل الأجهزة أو webhooks:
{ "data": [ { "id": "msg_q8v2k4n6p1r3t5w7y9z0b2c4", "status": "delivered" }, { "id": "msg_h3j5l7n9q2s4u6w8y1a3c5e7", "status": "sent" } ], "nextCursor": "bXNnX2gzajVsN245cTJzNHU2dzh5MWEzYzVlNw"}تكون nextCursor بالقيمة null في الصفحة الأخيرة. القوائم مرتبة من الأحدث إلى الأقدم.
المعاملات
Section titled “المعاملات”| الاستعلام | الافتراضي | النطاق | الوصف |
|---|---|---|---|
limit |
50 | من 1 إلى 200 | عدد العناصر في الصفحة. |
cursor |
قيمة nextCursor من الصفحة السابقة. اتركه في الصفحة الأولى. |
تعامل مع المؤشر كنص مبهم ومرّره كما وصلك تماما. المؤشر الذي لم تصدره الواجهة البرمجية يعيد 400 invalid_cursor. حافظ على عوامل التصفية نفسها في كل الصفحات، فتغييرها في المنتصف يعطي نتائج غير متسقة.
التصفح بالمؤشر مستقر أثناء وصول عناصر جديدة. الرسالة التي تُنشأ أثناء تصفحك تظهر في بداية القائمة، فلا تزيح الصفحات التي تقرأها.
استعراض كل الصفحات
Section titled “استعراض كل الصفحات”cursor=""while :; do page=$(curl -s "https://api.smsfabric.com/v1/messages?status=failed&limit=200${cursor:+&cursor=$cursor}" \ -H "X-Api-Key: $SMSFABRIC_API_KEY") echo "$page" | jq -r '.data[] | "\(.id) \(.errorCode)"' cursor=$(echo "$page" | jq -r '.nextCursor // empty') [ -z "$cursor" ] && breakdoneimport { SMSFabric } from '@smsfabric/sdk';
const sf = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
// listAll follows nextCursor for you.for await (const message of sf.messages.listAll({ status: 'failed', limit: 200 })) { console.log(message.id, message.errorCode);}
// Or one page at a time:const first = await sf.messages.list({ limit: 50 });if (first.nextCursor) { const second = await sf.messages.list({ limit: 50, cursor: first.nextCursor }); console.log(second.data.length);}import osimport requests
def list_all(path: str, **params): headers = {"X-Api-Key": os.environ["SMSFABRIC_API_KEY"]} params = {"limit": 200, **params} while True: res = requests.get(f"https://api.smsfabric.com{path}", headers=headers, params=params, timeout=30) res.raise_for_status() page = res.json() yield from page["data"] if not page["nextCursor"]: return params["cursor"] = page["nextCursor"]
for message in list_all("/v1/messages", status="failed"): print(message["id"], message["errorCode"])<?phpfunction listAll(string $path, array $params = []): Generator { $params += ['limit' => 200]; do { $ch = curl_init('https://api.smsfabric.com' . $path . '?' . http_build_query($params)); curl_setopt_array($ch, [ CURLOPT_HTTPHEADER => ['X-Api-Key: ' . getenv('SMSFABRIC_API_KEY')], CURLOPT_RETURNTRANSFER => true, ]); $page = json_decode(curl_exec($ch), true); yield from $page['data']; $params['cursor'] = $page['nextCursor']; } while ($page['nextCursor'] !== null);}
foreach (listAll('/v1/messages', ['status' => 'failed']) as $message) { echo $message['id'] . ' ' . $message['errorCode'] . "\n";}نقاط النهاية المقسمة إلى صفحات
Section titled “نقاط النهاية المقسمة إلى صفحات”هذه تقبل limit وcursor: GET /v1/messages وGET /v1/verifications وGET /v1/contacts وGET /v1/contact-groups وGET /v1/contact-imports وGET /v1/templates وGET /v1/campaigns وGET /v1/blacklist وGET /v1/webhooks/:id/deliveries وGET /v1/audit.
وهذه تعيد القائمة كاملة في صفحة واحدة مع nextCursor: null: GET /v1/devices وGET /v1/pools وGET /v1/webhooks وGET /v1/api-keys وGET /v1/org/members وGET /v1/org/invitations.
لنسخة كاملة من سجل رسائلك، يبث GET /v1/messages/export.csv كل الصفوف المطابقة في استجابة واحدة.