DataMatrix, QR, Code 128, GS1-128 and EAN over HTTP: send an image, get the codes. With GS1 field parsing and a structure check of Chestny ZNAK marking codes. The same readers as in our libraries.
POST /v1/decode. The image is a JPEG or PNG up to 8 MB, 4096 px on a side and 16 megapixels: as the request body, as the image field of multipart/form-data, or in JSON — image_base64 or an image_url link.
# An image file: JPEG or PNG as the request body
curl https://api.libscanner.com/v1/decode?gs1=true \
-H "Authorization: Bearer lsk_live_…" \
-H "Content-Type: image/jpeg" \
--data-binary @label.jpgParameters go in the query string, as form fields or as JSON fields:
mode | single — the first code found, fast (default); multi — every code in the image, up to 64 |
|---|---|
symbologies | what to look for, comma-separated: datamatrix, qr, code128, gs1-128, ean; everything by default |
budget_ms | time budget per image, 100–3000 ms, 1000 by default; the applied budget is returned in the response |
gs1 | true — GS1 field parsing and a structure check for every code |
lang | ru or en — language of field names and check messages |
An image by URL, all codes in it:
curl https://api.libscanner.com/v1/decode \
-H "Authorization: Bearer lsk_live_…" \
-H "Content-Type: application/json" \
-d '{"image_url": "https://example.com/label.jpg", "mode": "multi", "gs1": true}'{
"status": "ok",
"elapsed_ms": 41,
"budget_ms": 1000,
"codes": [{
"symbology": "datamatrix",
"text": "0104601234567893215Abc12Xyz!-\u001d93dGVz",
"text_hri": "(01)04601234567893(21)5Abc12Xyz!-(93)dGVz",
"bytes_base64": "MDEwNDYwMTIzNDU2Nzg5MzIxNUFiYzEyWHl6IS0dOTNkR1Z6",
"quad": [[212.5, 98.0], [431.0, 101.5], [428.5, 320.0], [210.0, 316.5]],
"gs1": {
"fields": {"01": "04601234567893", "21": "5Abc12Xyz!-", "93": "dGVz"},
"elements": [{"ai": "01", "name": "GTIN", "value": "04601234567893"}, …],
"check": [{"level": "ok", "text": "GTIN 04601234567893: контрольная цифра верна."}, …]
}
}],
"usage": {"day": 12, "day_limit": 1000, "month": 340, "month_limit": 10000}
}The GS separator in text is the real character (U+001D), not the text “<GS>”; the exact bytes of the symbol are in bytes_base64 and its corners in the image in quad. status: ok — a code was read, not_found — no code was found, not_decoded — a symbol was found but could not be read.
POST /v1/generate. DataMatrix by default; symbology = qr gives a QR Code (error correction level — ecc: L, M, Q or H, H by default). For DataMatrix, with gs1 set to gs1 or cz the data is validated against the GS1 rules (cz adds the Chestny ZNAK profile) and encoded as GS1 DataMatrix; invalid data gives a 422 answer with an explanation. The answer is a PNG; with Accept: application/json it is JSON with the image in base64 and its dimensions.
curl https://api.libscanner.com/v1/generate \
-H "Authorization: Bearer lsk_live_…" \
-H "Content-Type: application/json" \
-d '{"data": "(01)04601234567893(21)5Abc12Xyz!-(93)dGVz", "gs1": "cz", "module_px": 10}' \
-o code.pngPOST /v1/gs1/parse — no image needed: GS1 fields, the GTIN check digit, serial number length and characters, presence and lengths of the verification codes (91 + 92 or 93), missing separators, the expiry date. The format is checked; the status of the item in the marking system is not queried.
curl https://api.libscanner.com/v1/gs1/parse \
-H "Authorization: Bearer lsk_live_…" \
-H "Content-Type: application/json" \
-d '{"code": "0104601234567893215Abc12Xyz!-<GS>93dGVz"}'import requests
API = "https://api.libscanner.com/v1"
HEADERS = {"Authorization": "Bearer lsk_live_…"}
with open("label.jpg", "rb") as f:
r = requests.post(f"{API}/decode", params={"mode": "multi", "gs1": "true"},
headers={**HEADERS, "Content-Type": "image/jpeg"}, data=f)
r.raise_for_status()
for code in r.json()["codes"]:
print(code["symbology"], code.get("text_hri") or code["text"])
for item in (code.get("gs1") or {}).get("check", []):
print(" ", item["level"], item["text"])Соединение = Новый HTTPСоединение("api.libscanner.com", 443,,,,, Новый ЗащищенноеСоединениеOpenSSL);
Запрос = Новый HTTPЗапрос("/v1/decode?gs1=true");
Запрос.Заголовки.Вставить("Authorization", "Bearer lsk_live_…");
Запрос.Заголовки.Вставить("Content-Type", "image/jpeg");
Запрос.УстановитьТелоИзДвоичныхДанных(Новый ДвоичныеДанные("C:\label.jpg"));
Ответ = Соединение.ОтправитьДляОбработки(Запрос);
Чтение = Новый ЧтениеJSON;
Чтение.УстановитьСтроку(Ответ.ПолучитьТелоКакСтроку());
Результат = ПрочитатьJSON(Чтение);
Для Каждого Код Из Результат.codes Цикл
Сообщить(Код.text_hri);
КонецЦикла;Limits are per account and shared by all its keys. The day starts at 00:00 Moscow time. In addition, each key is limited to 5 requests per second and 2 simultaneous requests.
| Plan | Price | Requests per period | Per day | |
|---|---|---|---|---|
| Free | 0 ₽ | 300 · calendar month | 30 | Get a key |
| API Start · 1 month | $12.08 / 30 days | 10,000 | 1,000 | Subscribe |
| API Start · 1 year | $122.06 / 365 days | 10,000 | 1,000 | Subscribe |
| API Business · 1 month | $36.50 / 30 days | 50,000 | 5,000 | Subscribe |
| API Business · 1 year | $366.17 / 365 days | 50,000 | 5,000 | Subscribe |
No VAT charged
More than 50,000 requests a month or a stream of camera frames? A library is cheaper and faster: it runs on your machine, with no network and no delay for uploading the image. Libraries →
The error shape is {"error": {"code", "message", "request_id"}}. code is stable, message is for humans.
401 INVALID_KEY | the key is missing, invalid or revoked |
|---|---|
403 SCOPE | the key has no permission for this method |
400 INVALID_PARAMETER | a request parameter is wrong |
413 IMAGE_TOO_LARGE | the image is over the limits |
415 UNSUPPORTED_IMAGE | the image is neither JPEG nor PNG |
422 GS1_INVALID, DATA_INVALID | the data for the code does not pass GS1 validation or does not fit into the symbol |
429 DAY_LIMIT, MONTH_LIMIT | the plan limit is exhausted; the answer carries usage and Retry-After |
429 RATE_LIMIT, CONCURRENCY_LIMIT | too many requests per second or at once; with Retry-After |
503 BUSY | the server is busy; with Retry-After, the request is not counted |
Chestny ZNAK and GS1 are trademarks of their respective owners.