After upload, your ERP needs ingestion outcome and Peppol clearance without calling Marmin APIs. Poll sent_archive index files and artifact folders instead.
State machine
Upload placed in sent_inbox
│
▼
Index file missing ─────────────► still ingesting (poll)
│
▼
Index present
│
├─ ingestion_status = FAILURE ─► fix data, new filename, re-upload
│
└─ ingestion_status = SUCCESS
│
├─ peppol_status = NULL ─► Peppol in flight (poll)
│
└─ terminal peppol_status ─► sync ERP, fetch PDF/XML, stop polling rowWhat to write back to the ERP
Key reconciliation fields (map to your ERP columns):
Artifact download checklist
When ingestion_status = FAILURE or peppol_status = `NA`, read `ingestion_message` only — `retrieval_path` is `NA`; do not list or download artifact folders.
After ingestion_status = SUCCESS and peppol_status is terminal (ACCEPTED, REJECTED, or VALIDATION_FAILED):
Read
retrieval_pathfrom the index (must not beNAorPURGED).List the folder:
ls {retrieval_path}over SFTP.Download by document kind (prefix `Invoice` for sales invoice / self-billed purchase invoice; `Credit_note` for credit notes):
Use the same retrieval_path string from the index as the SFTP path prefix (it already includes sent_archive/...).
Polling interval
Stop polling a row when peppol_status is terminal or when retrieval_path is PURGED.
Shell example (JSON index)
Adjust credentials and stems. Requires jq, OpenSSH sftp, and lftp (or extend the sftp batch).
#!/usr/bin/env bash
set -euo pipefail
HOST="<sftp-host>"
PORT="<port>"
USER="<username>"
UPLOAD_STEM="inv-20260326-001" # basename without extension
INDEX="sent_archive/${UPLOAD_STEM}_index.json"
LOCAL_INDEX="/tmp/${UPLOAD_STEM}_index.json"
sftp -P "$PORT" -b - "${USER}@${HOST}" <<EOF
get ${INDEX} ${LOCAL_INDEX}
bye
EOF
jq -c 'if type=="array" then .[] else . end | {
document_number,
document_uuid,
ingestion_status,
ingestion_message,
peppol_status,
retrieval_path
}' "$LOCAL_INDEX"For each SUCCESS row with a non-null retrieval_path (and not PURGED), fetch artifacts:
REMOTE_PATH="sent_archive/100234567890003/ORACLE/invoice/550e8400-e29b-41d4-a716-446655440000"
sftp -P "$PORT" -b - "${USER}@${HOST}" <<EOF
get ${REMOTE_PATH}/Invoice.pdf /tmp/Invoice.pdf
get ${REMOTE_PATH}/Invoice_response.json /tmp/Invoice_response.json
bye
EOFWire the JSON fields into your ERP API or database update script.
XLSX indexes
Download
{stem}_index.xlsx.Convert to CSV (
ssconvert, LibreOffice headless, or Python/pandas in your stack).Parse rows where
ingestion_statusorIngestion Status(if localized) equalsSUCCESS.
Grouping: multiple rows may share one document_uuid—update ERP once per UUID or per line depending on your process.
Reconciliation checklist
[ ] Map upload stem → index filename (
{stem}_index.{ext})[ ] Persist
document_uuidon SUCCESS before Peppol completes[ ] Do not mark ERP invoice as "cleared" until
peppol_statusis terminal[ ] On REJECTED, attach
_response.jsoncontent to ERP case management[ ] Archive PDF/XML locally before 60-day SFTP retention
