View prompt
Integrate my existing application with the Biz On Demand client REST API. Inspect my repository first and use its existing framework, server runtime, conventions, and test tools. Do not replace unrelated code.
API base URL: https://bizondemand.ai/api/public/v1
Use this base URL for new integrations. If my existing integration uses another connected API hostname, preserve its working URL, endpoint paths and key; no migration is required. Do not automatically rewrite existing connection settings.
Public reference: https://bizondemand.ai/docs/api
Read the reference before implementing; do not invent endpoints or response fields. If you cannot access it, ask me to paste the relevant reference.
Security: use BIOSYNC_API_BASE_URL and BIOSYNC_API_KEY as server-only environment variables. Send Authorization: Bearer <BIOSYNC_API_KEY>. Real keys start with pl3pl_live_. Create an example environment file with placeholders only, exclude real secrets from version control, and never ask me to paste a key into this chat. Never put keys in browser code, public-prefixed variables, logs, or screenshots. Call the canonical base URL directly; do not follow cross-host redirects with credentials. Keep my application's normal user authorization on any proxy endpoints.
Use mocked API responses for automated tests, plus the documented isolated /test/orders API for scenario checks. The normal /orders endpoint creates real orders; never infer test mode from a reference, and never submit test fields to live /orders. No live order submission, label purchase, cancellation, or other account-changing calls without my explicit approval. Keep test and production paths/configuration explicit and separate. Document the setup and clearly distinguish simulated checks from real read-only checks.
Build the full integration in small stages: a server-only API client, catalog and COA sync, checkout shipping options, paid-order fulfillment, then tracking sync.
Catalog contract:
- GET /products?limit=100&offset=0 returns { products, total, limit, offset }. Products include sku, name, category, origin, in_stock, quantity_available, price, recommended_sell_price.
- Paginate until the reported total is collected or a page is empty; do not silently truncate to the first 100 products. Optional category is an exact-match filter.
- GET /inventory?limit=100&offset=0 returns { client, count, limit, offset, items }; items include sku, name, quantity_available, your_price, msrp. Do not confuse this shape with /products.
- GET /inventory/{sku} returns the single SKU's quantity_available and price. URL-encode the SKU.
- Use returned SKUs; do not synthesize codes or remap existing legacy connections. Stock and prices are scoped to the API key's account. Product price / inventory your_price is the fulfillment price, not the storefront retail price; recommended_sell_price / msrp is only a retail suggestion and may be null. Preserve my existing retail pricing. Do not enable ordering for unavailable or zero-priced products.
COA contract:
- GET /coas?limit=50&offset=0 returns { count, total, limit, offset, items }; paginate all pages. Optional sku (including retired aliases), exact lot, updated_since (ISO timestamp), url_ttl (60–3600 seconds, default 900).
- GET /coas/{returned-uuid} returns { coa }; missing IDs return 404, invalid filters 422, missing/revoked keys 401. Missing SKUs return an empty list.
- The certificate library includes unlinked files. Linked SKU details and SKU filters are scoped to the account catalog. Fields include id, name, lot_number, file_name, file_type, is_image, file_url, image_url, document_url, url_expires_in_seconds, created_at, updated_at, skus and analysis (nullable).
- Sync all /products pages for the account's sellable catalog separately from the certificate library. Store certificates by id and attach them only using each certificate's explicit skus array and the catalog's returned SKU codes. Multiple SKUs can share a certificate. skus: [] means no visible product association: leave it unattached. Never guess from names, strengths, lots or analysis.product_name; show COA not available when a product has no linked certificate.
- This is a pull API, not a push/webhook sync. Schedule recurring full catalog and COA reads server-side; after all pages succeed, replace product-to-certificate links, including removal of links no longer returned. On partial failure, preserve the last successful snapshot and show it as stale.
- updated_since is inclusive and filters only coas.updated_at. Product reassignment, analysis-only changes and deletions are not reliably represented by that filter. Do not rely on it alone: use recurring full reconciliation. For incremental requests, save the sync-start timestamp, advance it only after all pages succeed and deduplicate by certificate ID.
- Download the actual PDF/image using file_url before expiry, or request a fresh URL. Do not send the API key to the signed file URL. Preserve lot/SKU associations and do not treat extracted analysis as a replacement for the certificate. Add tests for pagination, expired links, empty results and PDFs vs images.
Checkout contract:
- POST /shipping/rates accepts { ship_to: { city, state, postal_code, country }, items: [{ sku, quantity }] } and returns { mocked, package, rates }. Each rate includes carrier_code, service_code, amount, currency and estimated_days. Do not treat mocked rates as production quotes.
- POST /orders accepts { client_order_id, customer: { name, email, phone }, ship_to: { name, line1, line2, city, state, postal_code, country }, items: [{ sku, quantity }], currency: "USD", notes }.
- Quantity is a positive whole number in vials, not kits. Map any kit quantity using a verified configured conversion, never guess. Do not send unit_price: fulfillment pricing is resolved by the API from the account's assigned prices.
- For a selected rate, add shipping_selection: { carrier_code, service_code, amount_charged: selectedRate.amount }. Do not substitute customer retail/free-shipping policy for fulfillment shipping cost. A shipping selection can purchase a label; do not add it without the intended checkout behavior being approved.
- Send only after my application's authoritative paid/approved checkout event. Persist one stable, non-UUID-prefixed client_order_id per storefront order (for example STORE-10245, max 120 characters) and reuse it for every retry. Persist the returned order.id; never generate a new reference to retry an uncertain result.
- Success returns { order, items, shipment, shipment_error }; a non-null shipment_error does not mean the order failed. Save the created order and surface the label problem, rather than creating a duplicate.
- Add timeouts and bounded exponential-backoff retries for transient failures with the same client_order_id. Stop and surface 401 authentication failures and 422 validation/unknown-SKU errors. Inspect other non-success responses instead of retrying blindly.
Tracking contract:
- GET /orders/{id} accepts the returned platform order ID or a non-UUID client_order_id. URL-encode the reference.
- Returns { order, items, tracking }. order includes id, client_order_id, status, shipping_status, cancellable, shipped_at, delivered_at; tracking is null until available, otherwise contains carrier, service_code, tracking_number, label_url.
- shipping_status is not_shipped, label_created, shipped, delivered, or cancelled. A created label is not proof of shipment.
- Poll from a server-side scheduled job using the host's supported scheduler, with configurable interval and bounded retries. Stop regular polling for delivered/cancelled orders. Persist status and tracking on the matching local order and avoid duplicate notifications. Do not fabricate a tracking URL or assume a dedicated tracking endpoint.
- Handle 404 as a missing order, not as an empty successful result. Keep previously saved status on transient failures and expose sync errors to staff.
- If proposing webhooks, first confirm the documented registration and signing-secret setup; do not invent a registration endpoint or claim polling is a webhook. Do not implement cancellation as part of this task.
Add mocked tests for pagination, secret isolation, SKU mapping, whole-number quantities, assigned fulfillment pricing, stable retry references, shipment_error handling, and tracking updates. Show me the changed files, required configuration and test results. List any missing business decisions before enabling live writes.