API: Minting
What It Does
The Minting API provides a single atomic gateway for submitting minting requests, along with lifecycle management for mint batches and units.
Authentication & Permissions
All RPCs require an authenticated session. Minting operations require a role with sufficient permissions for the target brand (typically admin or owner).
RPCs
submit_mint_request
The primary entry point for minting. Performs preflight validation, enforces ERP batch linkage, and atomically creates a mint job + mint batch.
Request
Response (success)
Response (blocked)
Response (idempotent hit)
Parameters
Errors
- Not authenticated — request has no valid JWT.
- Forbidden — caller does not have sufficient access.
- Invalid input — request is malformed or cannot be processed.
Notes
- Product must have
commercial_status = ACTIVEandmint_readiness_status = READY. - If
_product_batch_idis provided:- Production batch must exist and belong to the brand/product.
- Production batch must have
status = READY. - If the production batch has a quantity set, the requested quantity must not exceed it.
- If
_product_batch_idis null:- ERP checks are bypassed entirely.
- Only the platform safety limit (1,000,000 units) is enforced.
- In serial mode,
_lotsmust not be provided. - No mint units are created in this step — the async executor handles unit generation in the next slice.
preflight_mint_batch
Runs a preflight check against a product and batch to determine minting eligibility.
preflight_mint_batch is a standalone check. For submitting actual mint requests, use submit_mint_request which absorbs preflight validation.
Request
Response (pass)
Errors
- Not authenticated — request has no valid JWT.
- Forbidden — caller does not have sufficient access.
- Invalid input — request is malformed or cannot be processed.
create_mint_batch_from_job (DEPRECATED)
Deprecated. Use submit_mint_request instead. This RPC is retained for backward compatibility only.
Creates a mint batch linked 1:1 to a completed preflight mint job. Gate check patched to accept QUEUED and PREFLIGHTED statuses.
set_mint_batch_status (planned — not yet exposed via public API)
Transitions a mint batch to a new lifecycle status with audit trail.
Status values: draft → minted → exported → printed → applied → voided
list_mint_batches
Paginated listing of mint batches for a brand with deterministic cursor-based pagination.
Request
Response
Parameters
Errors
- Not authenticated — request has no valid JWT.
- Forbidden — caller does not have sufficient access.
list_mint_units
Paginated listing of mint units for a brand, with optional batch filter and deterministic cursor-based pagination.
Request
Response
Parameters
Errors
- Not authenticated — request has no valid JWT.
- Forbidden — caller does not have sufficient access.
list_mint_events
Paginated listing of mint events (activity/audit) for a brand with deterministic cursor-based pagination and optional filters.
Request
Response
Parameters
Errors
- Not authenticated — request has no valid JWT.
- Forbidden — caller does not have sufficient access.
record_scan_event (planned — not yet exposed via public API)
Records a scan telemetry event. Will be called by the edge resolver in a future slice.
process_mint_job_batch
The async mint executor database engine. Claims a queued mint job, generates identities in bounded chunks, and advances statuses deterministically.
Request
Response (in-progress)
Response (completed)
Parameters
Mode behaviour
Status transitions: QUEUED → RESERVED → PROCESSING → COMPLETED (or FAILED)
Events emitted: mint_job_started, mint_units_created, mint_lots_confirmed, mint_job_completed, mint_job_failed
This RPC is the database engine only. The background runner that invokes it in a loop is handled by the platform’s job scheduler.
API Exposure Policy
All minting mutation RPCs require an authenticated JWT. Anonymous or public execution is explicitly disallowed for the minting control plane.
Resolver endpoints are public and callable without authentication. They include internal tenant validation. No minting control-plane RPC is anonymously callable.
get_mint_kpis
Returns aggregate KPI values for the minting dashboard.
Request
Response
Parameters
Calculation rules
Notes
list_mint_batchesreturns a wrapped object with the canonical keybatches:{ "ok": true, "batches": [...], "has_more": bool, "next_cursor": string|null }.- Both
list_mint_batchesandlist_mint_unitsincludeproduct_skuper record, avoiding N+1 queries. If the product is missing,product_skuisnull.
get_mint_batch_by_id
Returns a single mint batch by ID, including joined product metadata (product_sku, product_name).
Request
Response (success)
Parameters
Errors
- Not authenticated — request has no valid JWT.
- Forbidden — caller does not have sufficient access.
- Invalid input — request is malformed or cannot be processed.
Notes
- Access is enforced at the server level to prevent cross-brand access (BOLA/IDOR safe).
- Includes
product_nameandproduct_skuin the response, avoiding N+1 queries. list_mint_unitsresponse uses canonical keyunits:{ "ok": true, "units": [...] }.
list_payload_packs
Paginated listing of payload packs (export artifacts) for a brand with deterministic cursor-based pagination.
Request
Response
Parameters
Errors
- Not authenticated — request has no valid JWT.
- Forbidden — caller does not have sufficient access.
- Invalid input — request is malformed or cannot be processed.
Notes
- Access is enforced at the server level to prevent cross-brand access (BOLA/IDOR safe).
storage_pathis returned as a relative path. No signed URLs are generated by the list endpoint.list_payload_packsresponse uses canonical keypacks:{ "ok": true, "packs": [...] }.
Payload Pack Downloads
Payload pack artifacts are stored in a private storage bucket. Downloads require authenticated access and use time-limited signed URLs.
Download Flow
storage_path may be null for packs in pending status. Always guard against null before requesting a signed URL.
Search (MVP)
search_brand_objects_v1
A brand-scoped global search RPC that returns a unified list of tokens, batches, exports, and products matching a query string.
Request
Response
Parameters
Matching rules
Notes
- Products are returned on the first page only (when no cursor is provided) and do not participate in cursor pagination.
- Product name search is not included in the MVP. Full-text or substring search will be added in a future release.
- Cursor-based pagination is index-backed for optimal read performance at enterprise scale.
Global Search (MVP)
The platform exposes a brand-scoped global search surface powered by the search_brand_objects_v1 RPC.
Behaviour
- Prefix-only matching — all queries use prefix search (
query%). No fuzzy matching, no full-text search, and no leading-wildcard (%query%) patterns. - Top 20 results — the MVP returns at most 20 results per query. No pagination is exposed in the UI.
- Brand-scoped security — every search request is scoped to the authenticated user’s current brand via
has_brand_access. Cross-brand search is not possible. - Object types — tokens, batches, exports, and products are searchable. Product results appear on the first page only.
- Minimum query length — queries shorter than 2 characters return an empty result set.
Mint API v1 (Submit + Kick)
A Backend-For-Frontend edge function that combines minting submission and immediate execution into a single call.
Endpoint
POST /functions/v1/mint-api-v1
Authentication
Requires a valid JWT in the Authorization: Bearer <token> header. The caller must have an owner or admin role for the target brand.
Request Body
Success Response (200)
Error Response (4xx/5xx)
Error Codes
Kick Behaviour
After a successful submit, the function performs exactly one bounded processing cycle (up to 20,000 units). The kicked field indicates whether this synchronous processing step succeeded.
kicked=false does not mean the job is lost. The platform’s background job scheduler runs on a regular schedule and will pick up any queued jobs. The synchronous kick is a latency optimisation, not a requirement for job completion.