وثائق API
نقطة نهاية واحدة تحول ZPL إلى PNG أو PDF. إنها متوافقة مع واجهة برمجة التطبيقات v1 من Labelary: نفس المسارات، الرؤوس والأخطاء.
تقديم تسمية
GET https://api.openzpl.com/v1/printers/{dpmm}/labels/{width}x{height}/{index}/{zpl}
POST https://api.openzpl.com/v1/printers/{dpmm}/labels/{width}x{height}/{index}
POST https://api.openzpl.com/v1/printers/{dpmm}/labels/{width}x{height}/
dpmm | كثافة الطباعة: 6dpmm, 8dpmm, 12dpmm, 24dpmm. |
width, height | حجم الملصق بالبوصات، على سبيل المثال 4x6 أو 2.25x1.25. حتى 15 بوصة لكل منها. |
index | أي ملصق يجب تصوره، بدءًا من 0. اتركه عند إخراج PDF للحصول على كل ملصق، واحد لكل صفحة. |
zpl | For GET, the URL-encoded ZPL. Encode # as %23. Use POST for anything long. |
باستخدام POST، أرسل ZPL كجسم طلب خام، أو كحقل نموذج متعدد الأجزاء يسمى file.
مفاتيح API
بدون مفتاح تحصل على الحدود المجانية لكل عنوان IP. مع مفتاح من لوحة التحكم الخاصة بك، أرسله في رأس X-API-Key ويطبق عليك حدود خطة مساحة العمل الخاصة بك.
curl https://api.openzpl.com/v1/printers/8dpmm/labels/4x6/0/ \ -H "X-API-Key: oz_live_…" --data-binary @label.zpl > label.png
أمثلة
# PNG from a short ZPL string curl --get https://api.openzpl.com/v1/printers/8dpmm/labels/4x6/0/ \ --data-urlencode "^xa^cfa,50^fo100,100^fdHello World^fs^xz" > label.png # PDF with every label in a file curl https://api.openzpl.com/v1/printers/8dpmm/labels/4x6/ \ -H "Accept: application/pdf" --form file=@labels.zpl > labels.pdf
import requests
zpl = "^xa^cfa,50^fo100,100^fdHello World^fs^xz"
res = requests.post("https://api.openzpl.com/v1/printers/8dpmm/labels/4x6/0/", data=zpl)
res.raise_for_status()
open("label.png", "wb").write(res.content)const zpl = "^xa^cfa,50^fo100,100^fdHello World^fs^xz";
const res = await fetch("https://api.openzpl.com/v1/printers/8dpmm/labels/4x6/0/", {
method: "POST",
headers: { Accept: "application/pdf" },
body: zpl,
});
await require("fs/promises").writeFile("label.pdf", Buffer.from(await res.arrayBuffer()));$zpl = "^xa^cfa,50^fo100,100^fdHello World^fs^xz";
$ch = curl_init("https://api.openzpl.com/v1/printers/8dpmm/labels/4x6/0/");
curl_setopt_array($ch, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => $zpl, CURLOPT_RETURNTRANSFER => true]);
file_put_contents("label.png", curl_exec($ch));رؤوس الطلب
| رأس | القيم | افتراضي |
|---|---|---|
Accept | image/png, application/pdf | PNG |
X-Quality | Grayscale (8 بت، حواف ناعمة) أو Bitonal (1 بت، ملفات أصغر) | Grayscale |
X-Rotation | 0, 90, 180, 270، في اتجاه عقارب الساعة | 0 |
X-API-Key | مفتاح مساحة العمل الخاصة بك، اختياري | — |
Limits
- Free, no sign-up and no key: 3 requests per second and 5,000 labels per UTC day, per IP address.
- Labels, not requests, count against the daily allowance: every label rendered,
^PQcopies and PDF pages included. A 10-label PDF is 1 request and 10 labels. - Every request: up to 50 labels, a 1 MB body, 15 inches per side, and 10 seconds of render time.
- Paid plans (Starter $9/month: 10 requests/s and 25,000 labels/day, Pro $29/month: 10 requests/s and 100,000 labels/day, Business $99/month: 20 requests/s and 500,000 labels/day) are announced but billing isn't live yet. API keys work today; a workspace stays on the Free plan until billing opens.
- Over a limit the API answers
429withRetry-After(seconds) and a body that names the limit, e.g.ERROR: Daily limit reached: 5000 labels per UTC day on this plan (^PQ copies and PDF pages count).
الردود والأخطاء
الردود الناجحة تحمل X-Total-Count، عدد الملصقات التي تنتجها ZPL، مع ^PQ نسخ مضمنة. الأخطاء هي نص عادي يبدأ بـ ERROR:.
| الحالة | المعنى |
|---|---|
| 400 | معامل غير صالح، أو أن التسمية كبيرة جدًا، أو أن الفهرس خارج النطاق. |
| 401 | مفتاح API غير معروف أو تم إلغاؤه. |
| 406 | يطلب رأس Accept تنسيق إخراج غير متاح بعد. |
| 413 | حجم الجسم أكثر من 1 ميجابايت، أو ينتج ZPL أكثر من 50 ملصق. |
| 429 | الكثير من الطلبات أو الملصقات لخطة اشتراكك. انتظر عدد الثواني في Retry-After. |
| 503 | استغرق الملصق أكثر من 10 ثوانٍ للتقديم، أو الخدمة مشغولة. حاول مرة أخرى، أو قلل الكثافة أو الحجم. |
OpenAPI and Markdown
The same contract is published as OpenAPI 3.1 and as Markdown, for code generators and coding assistants.
Step-by-step guides: Python, Node.js, PHP, C#. Moving from Labelary: migration guide.