Send a receipt and retrieve its result
POST sends your document. GET retrieves the result. Follow this example for the complete workflow.
Check service health first. If mode = CABINETS_ONLY or recognition_ready = false, recognition is not enabled. Do not upload documents yet.
1. Get an API key
Create a client connection in the cabinet, for example My Shop. Use tenant_id my-shop. Save the connection API key starting with mr. Use this key, not your cabinet password, for API calls.
2. Prepare a receipt
Place check.jpg and manifest.json in the same folder. One physical receipt is one receipts entry. If a long receipt spans several photographs, list their filenames within one entry. Example:
{
"tenant_id": "my-shop",
"request_id": "demo-001",
"receipts": [
{
"client_receipt_id": "receipt-001",
"files": [
"check.jpg"
]
}
]
}3. POST — upload the receipt
Open a terminal in the folder containing the files. The commands below use Bash. Enter your API key at the hidden terminal prompt. The request sends your receipt and its manifest:
bash
read -r -s -p "API key: " RECEIPT_API_KEY
printf '\n'
BASE=https://osr.magla.ru
curl -sS -X POST "$BASE/v1/receipts" \
-H "Authorization: Bearer $RECEIPT_API_KEY" \
-F 'manifest=<manifest.json' \
-F 'files=@check.jpg;filename=check.jpg;type=image/jpeg' \
-o accepted.json -w 'HTTP %{http_code}\n'
python3 -m json.tool accepted.json4. GET — retrieve JSON
HTTP 202 confirms acceptance, not successful recognition. Read batch_id from accepted.json. GET returns status and completed results. Repeated GET calls do not charge another receipt unit.
BATCH_ID=$(python3 -c 'import json; print(json.load(open("accepted.json"))["batch_id"])')
curl -sS "$BASE/v1/batches/$BATCH_ID" \
-H "Authorization: Bearer $RECEIPT_API_KEY" \
-o result.json -w 'HTTP %{http_code}\n'
python3 -m json.tool result.jsonFor a single receipt, use GET /v1/receipts/{receipt_id}.
5. Save the result
For COMPLETED or PARTIAL_USABLE, check usable, validation, warnings and document. The document includes supplier, items, payment and totals. Do not import an unusable document as verified data.
6. ACK — acknowledge receipt
After saving the result in your own system, acknowledge it. ACK never dispatches recognition again. Results are available for 720 hours (30 days). Repeated GET or ACK does not extend retention.
RECEIPT_ID=$(python3 -c 'import json; print(json.load(open("result.json"))["receipts"][0]["receipt_id"])')
curl -sS -X POST "$BASE/v1/receipts/$RECEIPT_ID/ack" \
-H "Authorization: Bearer $RECEIPT_API_KEY" \
-o /dev/null -w 'HTTP %{http_code}\n'7. A batch of ten receipts
One manifest accepts up to 50 physical receipts. For ten separate photographs, provide ten distinct client_receipt_id entries and ten files parts. Filenames must match the manifest. Multiple photos of a single receipt remain one receipt. When retrying an uncertain upload, keep the same request_id, receipt identifiers and original bytes.
JPEG, PNG, WebP and PDF. Up to 10 MB per file, 20 MB per receipt, 200 MB per batch, and 10 files per receipt.
8. Errors
401: check the API key. 403: tenant mismatch. 402: subscription required. 409: conflicting identifiers or quota exhausted. 410: expired result. 413: oversized file or batch. 429: service busy. 503: service temporarily unavailable. Never create a new paid request after an uncertain submission.