# Commerce Assistant Pro — Fiscal / ERP API v1 Documentation revision: 2026-11-07, Pro 0.14.3 Stable candidate with Free 0.12.10 / Core API 1.9.0. Namespace: `leanmerce-compliance/v1`. Companion specification: `fiscal-erp-openapi-v1.json`. Start with `API-DEVELOPER-GETTING-STARTED.md` for the merchant/developer seven-step workflow and the available/omitted data sufficiency table. The source-only synthetic connector verifier is in the delivery evidence, never the installable ZIP. The Pro Fiscal / ERP screen links to this exact bundled guide and OpenAPI using an authenticated, nonce-protected, read-only endpoint. Website publication is optional and pending; no invented public documentation URL is required. The separate Additional fields screen links to the Document Extension API guide. Neither screen enables integration commands by opening documentation. This is an integrator interface, not a built-in connector for 5D, PANTHEON, Datalab or any POS/ERP. Enabling settings alone does not create such a connection or issue a fiscal receipt. The merchant's integrator implements the external connection. No new licensing protocol is introduced. ## Deployment and authorization Use the merchant's existing WordPress HTTPS origin. The base path is `/wp-json/leanmerce-compliance/v1`, or the equivalent WordPress `?rest_route=/leanmerce-compliance/v1/...` routing when pretty permalinks are unavailable. The host plugin does not send requests to these example URLs. Both production bridge and REST access must be enabled explicitly. Both default to OFF. The provider identifier must be on the merchant's allowlist. A remote provider need not be a local PHP provider; the admin screen lists only PHP providers actually registered in this installation. Authenticate using normal WordPress authentication, preferably a dedicated user with an Application Password and the `lmcc_manage_integrations` capability. Do not use a customer's account or share the administrator's password. This is a deliberate site-wide integration permission, not a customer-order ownership permission: a granted integrator may read authorized fiscal contexts for orders across the shop. Ordinary order owners and unrelated customers do not obtain this capability through ownership. Application Password requests use HTTP Basic authentication over HTTPS. They do not require a browser nonce. Cookie-authenticated REST clients must satisfy WordPress's own REST nonce/authentication rules. There is no custom anonymous, license-token or bearer-token bypass. Revoke the Application Password and capability when access is no longer needed. Writes also require an active `fiscal_bridge` entitlement or the existing persisted, exact operation grant for the started fiscalization operation. A supplied snapshot UUID/hash alone never grants permission. The original order snapshot remains immutable. ## Implemented routes | Method | Path | Purpose | | --- | --- | --- | | GET | `/orders/{order_id}/fiscalization?provider={provider_id}` | Obtain the latest sealed fiscalization context. | | POST | `/orders/{order_id}/external-documents` | Register an external PDF upload or reference against an exact sealed snapshot. | | POST | `/orders/{order_id}/fiscal-events` | Append one immutable, provider-attributed fiscal/ERP event against an exact sealed snapshot. | | GET | `/orders/{order_id}/fiscal-events?provider={provider_id}&cursor=0&limit=100` | Read a cursor-paginated page of the authenticated provider's accepted events. | There is no API here for creating an order, changing its status, rewriting a contract, uploading a template, fetching an external URL, listing all orders, or issuing a fiscal receipt. Do not infer additional endpoints from this document. ### GET fiscalization The order ID is a positive decimal integer in PHP's supported integer range. Provider must be a nonempty scalar string; WordPress normalizes it with `sanitize_key` and the configured provider allowlist is checked. Successful response is HTTP 200. The exact top-level keys are `order`, `snapshot`, `jurisdiction`, `contract_concluded_at_utc`, `items`, `totals`, `payment`, and `operation_key`. - `order`: `id`, public `number`, and `currency`. - `snapshot`: `id`, `uuid`, positive `revision`, and SHA-256 `hash`. - `jurisdiction`: `merchant` and `consumer`. - `items`: `item_id`, `sku`, `name`, numeric `quantity`, decimal-string `total`, and `total_tax`. Integral quantities retain their integer JSON representation; fractional quantities are preserved as JSON numbers rather than truncated. - `totals`: decimal strings `subtotal`, `discount_total`, `shipping_total`, `total_tax`, and `total`. - `payment`: `method` and `method_title`, not card or gateway credentials. - `operation_key`: `fiscalize:` followed by the snapshot UUID. This identifies an operation; it is not an authentication secret. This projection is derived from the sealed snapshot, not today's mutable order or product data. It deliberately excludes customer addresses, email, phone, legal text, license credentials and private-storage keys. Item descriptions/SKUs can still contain merchant-entered personal data: minimize logging and restrict access accordingly. ### POST external-documents Send `Content-Type: application/json` for reference registration or `multipart/form-data` for file upload. Every request requires `Idempotency-Key`, a nonempty trimmed value of at most 191 bytes. Reuse it for a retry of the same registration only. | Field | Type / meaning | | --- | --- | | `provider` | Required string, normalized provider ID on the allowlist. | | `document_type` | Required string, normalized external document type, e.g. `invoice`. | | `snapshot_revision` | Required positive integer, or canonical decimal string for multipart. Arrays, booleans and fractional numbers are rejected. | | `snapshot_uuid` | Required UUID of that exact order revision. | | `snapshot_hash` | Required 64-hex SHA-256 of that exact sealed snapshot. | | `external_reference` | Optional reference instead of an uploaded PDF. Up to 255 bytes: a sanitized HTTPS URL or an alphanumeric reference using `. _ : / -`. It is stored, not fetched. | | `file` | Optional multipart PDF, instead of an external reference. | | `external_id` | Optional external system ID; stored as plain text, limited to 191 bytes. | | `issue_date` | Optional string accepted by PHP date parsing. Prefer an explicit ISO-8601 date/time with timezone. | | `label` | Optional plain-text display label, limited to 160 bytes. | | `customer_visible` | Optional boolean, default false. Multipart Boolean strings are interpreted by PHP's `FILTER_VALIDATE_BOOLEAN`. | Use exactly one of `file` and `external_reference`. Scalar string fields are validated before casting. Additional unknown fields are ignored; they do not confer capabilities or alter the license. Metadata is escaped at presentation boundaries. The order, revision, UUID and hash must all bind to the same sealed snapshot. Do not use a newer revision's UUID/hash with an older revision number. Uploads default to 5 MiB; the merchant UI allows 1–10 MiB. The underlying configuration is clamped to 256 KiB–10 MiB. PHP/web-server limits may reject a request before the plugin receives it. Received length must match the declared upload length, and HTTP uploads must originate from PHP's upload mechanism. The validator checks PDF header, an EOF marker near the end, MIME, size, and its existing active/embedded-content denylist, including PDF `#xx` escaped names. It computes SHA-256 itself. This structural denylist is not an antivirus or complete PDF content-disarm engine; use trusted ERP/POS output and do not expose this as a public customer upload endpoint. Accepted PDF bytes use existing private encrypted storage. External documents remain distinct from the sealed Pro distance-sales contract. Registration never inserts late data into R1/R2, changes an order status, regenerates an original contract or sends an email by itself. ### Successful response and idempotency HTTP 201 returns `uuid`, `order_id`, `snapshot_id`, `provider`, `document_type`, `external_id`, `source_kind` (`reference` or `upload`), `file_hash` (null for a reference), `customer_visible`, and `created_at` (UTC). The effective identity is SHA-256 of provider, order ID and the supplied Idempotency-Key. An identical retry returns HTTP 201 and the same document UUID, not a second record. Reusing the key with different snapshot, metadata, reference, or file content returns 409. Do not generate a fresh key merely because a network response was lost. Read the saved response and retry the original request first. The host accepts a PDF hash as an integrity fingerprint, not a fiscal authority's cryptographic signature. Authentication, entitlement operation grants and the separately signed Pro updater remain different mechanisms. ## Structured fiscal-event routes The `fiscal-events` routes are distinct from external-PDF/reference registration. Both GET and POST require the enabled bridge/REST settings, the integration capability, an allowlisted provider and explicit provider-to-authenticated-user mapping. The mapping is required for reads as well as writes; the original fiscalization/external-document routes retain their existing authorization rules. POST accepts a JSON object of at most 8,192 bytes, not a multipart file. Use the `FiscalEventInput` schema in `fiscal-erp-openapi-v1.json` for its required fields, allowed event types and optional linked document/event identities. Send a stable `Idempotency-Key` matching `[A-Za-z0-9._:-]{1,191}`. Unknown fields are rejected; omit absent optional values instead of supplying null. An identical normalized provider/order/key or external-event identity returns the original event with HTTP 201; a conflicting payload returns 409. New writes require existing `fiscal_bridge` write authorization. An identical accepted retry can recover the previous commit without creating a second event. GET returns HTTP 200 with `order_id`, `provider`, `events`, `next_cursor` and `has_more`. The cursor is a nonnegative server integer, not an event UUID; limit defaults to 100 and must be between 1 and 100. Results are provider-scoped. Accepted history remains readable after entitlement expiry while the current bridge/REST, capability and provider-user checks still apply. This REST access is separate from merchant archive access. Events record information received from an authorized integrator; they do not issue fiscal receipts, update stock/payment/order status, send email or modify sealed snapshots and original documents. The companion OpenAPI describes the exact request/response fields and errors. No new route or protocol is introduced by this documentation correction. ## Developer workflow 1. Merchant approves the integration user, provider ID, capability and settings on an isolated test shop. 2. Integrator obtains a test order's context through the GET route. 3. Integrator creates the external document in its own ERP/POS, retaining the exact snapshot identity. 4. Integrator POSTs either its PDF or reference, with a stable idempotency key. 5. Integrator stores the returned UUID/hash and handles bounded retries. It does not edit the Pro contract or its historical rows. Minimal reference request example (placeholders only; no credential is shipped): POST /wp-json/leanmerce-compliance/v1/orders/123/external-documents Authorization: Basic Idempotency-Key: erp-example-order-123-r1-invoice-001 Content-Type: application/json {"provider":"erp-example","document_type":"invoice","snapshot_revision":1,"snapshot_uuid":"","snapshot_hash":"","external_reference":"ERP-INV-001","customer_visible":false} Replace placeholders with values from an actual authorized GET. A request where `provider` is an array is rejected with HTTP 400; an authenticated customer without the integration capability receives 403. A different snapshot hash is rejected with 409. Actual synthetic wire results, including a multipart PDF, are included in this delivery's verification bundle; these examples are not claimed as external production E2E. ## Errors and retries | HTTP | Typical meaning | | --- | --- | | 400 | Missing idempotency key, malformed JSON/types/snapshot identity, invalid upload/reference or rejected PDF content. | | 401 | WordPress authentication failure, such as an invalid/revoked Application Password. | | 403 | Bridge/REST disabled, missing capability or provider not allowlisted. | | 404 | No sealed snapshot for a GET, or no matching route/method. | | 409 | Exact-snapshot mismatch, conflicting retry, unavailable operation entitlement/storage or another state conflict. | | 413 | Received upload exceeds the plugin's configured size bound. | | 500 | Unexpected registration failure. | WordPress error bodies use `code`, `message` and `data.status`; localized message text is not a stable machine identifier. The error code and HTTP status are the integration surface. Correct 400/403/409 causes before retrying. For transport failures/5xx, use bounded exponential backoff and the same key; never implement an unlimited tight retry loop. ## Compatibility and publication The REST namespace remains v1 and the Document Extension Registry API remains 1.0. The latter is a different, trusted-installed-PHP API with `FORMATION_SNAPSHOT` and `POST_ORDER_CURRENT`; it is not a remote REST sandbox. Existing snapshots, grants, legal text, licenses and update hosts/keys are not migrated by these UX changes. Publication map: existing Leanmerce Documentation section → Commerce Assistant Pro → Integrations → Fiscal / ERP API v1, with this document and the companion OpenAPI artifact. This is a content map, not an invented live URL. Website publication and its exact existing CMS route remain `PUBLISH_PENDING`; no website or Platform change was performed and no Pro-development responsibility is delegated elsewhere.