{"openapi":"3.0.3","info":{"title":"Infoden Compliance Infrastructure API","version":"2.0.0","description":"Public REST API for partner integrations (ERPs, portals) to read Infoden client company, invoice, and compliance-deadline data, to submit company-registration intents, and (since Phase 2) to subscribe to webhooks for real-time domain events instead of polling. Authenticates with API keys, not Supabase session JWTs. Nothing this API does creates a company or sends outreach automatically — registrations land in the same human review queue as every other channel. Since Phase 1.5, a key's visibility is scoped by organization (not a single client_id): an organization can span multiple portal-user client_ids and multiple companies, and a scoped key sees everything under its organization. Since Phase 3, this API also exposes payments, registration status reads, and the document registry (list/get/download/upload/generate) — the same shared service layer the web app's JWT-authenticated app-actions gateway calls for its write paths (ledger posting, payment recording/allocation, status transitions), which is not itself part of this public surface."},"x-partner-events":["order.created","order.paid","stage.started","stage.completed","stage.delayed","stage.note","stage.action_needed","stage.rejected","names.rejected","order.registered","order.completed","order.cancelled","order.status_changed","order.priced","document.added","wallet.topped_up","wallet.topup_reversed"],"x-partner-test-mode":{"summary":"A test key (ick_test_...) works against a sandbox. Orders are validated and priced exactly like live, but nothing real is created: no company, no invoice, no wallet charge, and Infoden staff are not notified.","isolation":"Test keys see only test orders and test events, and live keys only live ones. A webhook endpoint created with a test key receives only test events. The same Idempotency-Key can be used once in each environment.","simulate":"POST /orders/{id}/simulate with action advance | reject_names | action_needed | add_document moves a test order along and sends the same webhooks a live order would (data.livemode = false).","magic_references":{"test_insufficient_funds":"returns the live 402 insufficient_funds","test_credit_limit":"returns the live 402 credit_limit_reached"},"note":"Test orders have no files to download, and uploads to them are validated but not stored. Every event carries data.livemode."},"x-webhook-guide":{"delivery":"POST { id, event_type, created_at, data } to the registered url. 10s timeout on our side.","headers":{"X-ICI-Event-Id":"The event's UUID — use this to de-duplicate; the same event may be delivered more than once (at-least-once delivery).","X-ICI-Timestamp":"Unix seconds the request was signed at.","X-ICI-Signature":"sha256=<hex HMAC-SHA256 of `${timestamp}.${raw_request_body}`, keyed with your webhook secret>."},"replay_protection":"Reject any request where |now - X-ICI-Timestamp| > 300 seconds (5 minutes), in addition to verifying the signature.","verify_node":"const crypto = require('crypto');\nfunction verify(rawBody, timestamp, signatureHeader, secret) {\n  const [, sig] = signatureHeader.split('sha256=');\n  const expected = crypto.createHmac('sha256', secret).update(`${timestamp}.${rawBody}`).digest('hex');\n  const fresh = Math.abs(Date.now() / 1000 - Number(timestamp)) <= 300;\n  return fresh && crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));\n}","verify_python":"import hmac, hashlib, time\ndef verify(raw_body: bytes, timestamp: str, signature_header: str, secret: str) -> bool:\n    sig = signature_header.split('sha256=')[-1]\n    expected = hmac.new(secret.encode(), f'{timestamp}.{raw_body.decode()}'.encode(), hashlib.sha256).hexdigest()\n    fresh = abs(time.time() - float(timestamp)) <= 300\n    return fresh and hmac.compare_digest(sig, expected)","retry_policy":"2xx = delivered. Anything else retries with backoff 1m, 5m, 30m, 2h, 12h (5 attempts total); after the 5th failed attempt the delivery is marked dead. If an endpoint accumulates 20 consecutive dead deliveries it is automatically set inactive (disabled_reason='auto_disabled_failures') — re-enable by deleting and re-creating the endpoint."},"servers":[{"url":"https://utqhqptzqcvodtphlmvn.supabase.co/functions/v1/api-v1"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"http","scheme":"bearer","bearerFormat":"ick_{live|test}_<random>","description":"Pass as `Authorization: Bearer ick_live_...`. A test key (`ick_test_...`) works against the sandbox described in x-partner-test-mode: nothing real is created or charged. Partners create both kinds in their dashboard (/partner -> API & webhooks)."}},"schemas":{"CatalogueItem":{"type":"object","properties":{"code":{"type":"string","example":"zw-standard"},"kind":{"type":"string","enum":["package","addon"]},"countries":{"type":"array","items":{"type":"string"}},"name":{"type":"string"},"includes":{"type":"array","items":{"type":"string"}},"currency":{"type":"string"},"retail_price":{"type":"number"},"your_price":{"type":"number"}}},"OrderRequest":{"type":"object","required":[],"properties":{"package":{"type":"string","example":"zw-standard","description":"A company registration. Send this or services."},"services":{"type":"array","description":"Anything else Infoden does. Send this or package.","items":{"type":"object","required":["code"],"properties":{"code":{"type":"string","example":"tax_clearance"},"qty":{"type":"integer","minimum":1,"maximum":50,"default":1}}}},"company_id":{"type":"string","format":"uuid","description":"Services only: one of your orders' companies."},"addons":{"type":"array","items":{"type":"string"},"example":["nssa"]},"reference":{"type":"string","description":"Your own order reference; echoed in every webhook."},"idempotency_key":{"type":"string"},"resale_price":{"type":"number","description":"What you charge your client (for your records only)."},"resale_currency":{"type":"string","example":"USD"},"end_client":{"type":"object","properties":{"name":{"type":"string"},"email":{"type":"string"},"phone":{"type":"string"}},"description":"Kept for your records. Infoden never contacts your client."},"details":{"type":"object","required":["proposed_names"],"properties":{"proposed_names":{"type":"array","items":{"type":"string"},"minItems":1,"maxItems":10},"business_purpose":{"type":"string"},"address":{"type":"string"},"company_phone":{"type":"string"},"company_email":{"type":"string"},"directors":{"type":"array","items":{"type":"object"}},"shareholders":{"type":"array","items":{"type":"object"}},"secretary":{"type":"object"}}}}},"Order":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"reference":{"type":"string"},"status":{"type":"string","enum":["pending","in_progress","completed","cancelled"]},"current_stage":{"type":"string"},"environment":{"type":"string","enum":["live","test"]},"livemode":{"type":"boolean"},"cancelled_at":{"type":"string","format":"date-time","nullable":true},"cancel_reason":{"type":"string","nullable":true},"refunded_amount":{"type":"number","description":"Put back in your wallet when Infoden cancelled the order."},"package":{"type":"string"},"addons":{"type":"array","items":{"type":"string"}},"wholesale_total":{"type":"number"},"currency":{"type":"string"},"billed_by":{"type":"string","enum":["wallet","invoice"]},"company":{"type":"object"},"invoice":{"type":"object"},"stages":{"type":"array","items":{"type":"object"}},"idempotent_replay":{"type":"boolean"}}},"Error":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","example":"unauthorized"},"message":{"type":"string"},"request_id":{"type":"string","format":"uuid"},"issues":{"type":"array","items":{"type":"object"},"nullable":true}},"required":["code","message","request_id"]}}},"Company":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"client_id":{"type":"string","format":"uuid"},"company_name":{"type":"string"},"company_type":{"type":"string","enum":["pbc","plc","ngo","trust","partnership","sole_trader"]},"registration_country":{"type":"string","enum":["zimbabwe","south_africa","zambia","dubai"]},"jurisdiction_code":{"type":"string","example":"ZW","description":"FK to Jurisdiction.code (ICI Phase 5)"},"registration_number":{"type":"string","nullable":true},"status":{"type":"string","enum":["draft","processing","completed","suspended","registered"]},"registration_date":{"type":"string","format":"date","nullable":true},"annual_return_date":{"type":"string","format":"date","nullable":true},"last_annual_return":{"type":"string","format":"date","nullable":true},"company_email":{"type":"string","nullable":true},"company_phone":{"type":"string","nullable":true},"address":{"type":"string","nullable":true},"contact_person_name":{"type":"string","nullable":true},"contact_person_email":{"type":"string","nullable":true},"contact_person_phone":{"type":"string","nullable":true},"is_priority_client":{"type":"boolean"},"completion_percentage":{"type":"number","nullable":true},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"}}},"Jurisdiction":{"type":"object","description":"ICI Phase 5","properties":{"code":{"type":"string","example":"ZW"},"name":{"type":"string","example":"Zimbabwe"},"status":{"type":"string","enum":["live","pilot","planned"],"description":"'live' = fully operational. 'pilot' = intake collected, delivered via a licensed local filing agent."},"default_currency":{"type":"string","example":"USD"},"registry_name":{"type":"string","nullable":true},"tax_authority_name":{"type":"string","nullable":true},"timezone":{"type":"string"},"notes":{"type":"string","nullable":true}}},"ServiceCatalogueItem":{"type":"object","description":"ICI Phase 5","properties":{"id":{"type":"string","format":"uuid"},"name":{"type":"string"},"category":{"type":"string","nullable":true},"subcategory":{"type":"string","nullable":true},"jurisdiction":{"type":"string","nullable":true,"description":"Legacy free-text value, kept for backward compatibility"},"jurisdiction_code":{"type":"string","nullable":true,"description":"FK to Jurisdiction.code. Null means available in every jurisdiction."},"description":{"type":"string","nullable":true},"standard_price":{"type":"number"},"currency":{"type":"string"},"price_suffix":{"type":"string","nullable":true},"turnaround_days":{"type":"integer","nullable":true},"turnaround_label":{"type":"string","nullable":true},"requirements":{"type":"array","items":{"type":"string"},"nullable":true},"is_active":{"type":"boolean"},"featured":{"type":"boolean"}}},"InvoiceLineItem":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"invoice_id":{"type":"string","format":"uuid"},"item_name":{"type":"string","nullable":true},"description":{"type":"string"},"quantity":{"type":"number"},"unit_price":{"type":"number"},"total":{"type":"number"},"service_id":{"type":"string","format":"uuid","nullable":true}}},"Invoice":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"invoice_number":{"type":"string"},"issue_date":{"type":"string","format":"date","nullable":true},"due_date":{"type":"string","format":"date","nullable":true},"status":{"type":"string"},"currency":{"type":"string"},"subtotal":{"type":"number"},"discount_amount":{"type":"number"},"tax_amount":{"type":"number"},"total_amount":{"type":"number"},"amount_paid":{"type":"number"},"payment_method":{"type":"string","nullable":true},"notes":{"type":"string","nullable":true},"terms":{"type":"string","nullable":true},"recipient_type":{"type":"string"},"client_id":{"type":"string","format":"uuid","nullable":true},"recipient_company_id":{"type":"string","format":"uuid","nullable":true},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"line_items":{"type":"array","items":{"$ref":"#/components/schemas/InvoiceLineItem"},"description":"Only present on GET /invoices/:id"}}},"CompanyPerson":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"full_name":{"type":"string"},"email":{"type":"string","nullable":true},"role":{"type":"string","enum":["director","shareholder","secretary","contact","beneficial_owner"]},"shareholding_percent":{"type":"number","nullable":true},"appointed_at":{"type":"string","format":"date","nullable":true},"resigned_at":{"type":"string","format":"date","nullable":true}},"description":"National ID, date of birth, and phone are deliberately excluded from this scope — a future `people:read:full` scope could expose them."},"Deadline":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"company_id":{"type":"string","format":"uuid","nullable":true},"type":{"type":"string"},"description":{"type":"string"},"due_date":{"type":"string","format":"date","nullable":true},"status":{"type":"string"}}},"RegistrationIntentRequest":{"type":"object","required":["companyName","companyType","jurisdiction","contact"],"properties":{"companyName":{"type":"string"},"companyType":{"type":"string","example":"pbc"},"jurisdiction":{"type":"string","example":"ZW","description":"Jurisdiction code or name — validated against GET /jurisdictions (ICI Phase 5); 'planned'/unknown codes are rejected."},"contact":{"type":"object","required":["name"],"description":"At least one of email or phone is required.","properties":{"name":{"type":"string"},"email":{"type":"string","format":"email"},"phone":{"type":"string"}}}}},"RegistrationIntentResponse":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"status":{"type":"string","enum":["received"]},"jurisdiction":{"type":"string","example":"ZW","description":"Resolved jurisdiction code (ICI Phase 5)."},"message":{"type":"string","description":"Honest status message — explicitly notes when a jurisdiction is 'pilot' (human-handled, no automated filing)."}}},"WebhookEndpoint":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"organization_id":{"type":"string","format":"uuid"},"url":{"type":"string","format":"uri"},"event_types":{"type":"array","items":{"type":"string"},"description":"Empty array = all event types."},"environment":{"type":"string","enum":["live","test"],"description":"Live endpoints receive live events only, test endpoints test events only. Set from the API key that created it."},"active":{"type":"boolean"},"created_at":{"type":"string","format":"date-time"},"secret":{"type":"string","description":"Only present in the POST /webhooks response — never returned again after creation."}}},"CreateWebhookRequest":{"type":"object","required":["url"],"properties":{"url":{"type":"string","format":"uri"},"event_types":{"type":"array","items":{"type":"string"},"description":"Omit or send [] to subscribe to all event types.","example":["invoice.paid","workflow.stage_changed"]}}},"Event":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"event_type":{"type":"string","example":"invoice.paid"},"aggregate_type":{"type":"string","example":"invoice"},"aggregate_id":{"type":"string","format":"uuid"},"payload":{"type":"object","description":"Event-specific snapshot — never includes credentials or raw officer JSON."},"created_at":{"type":"string","format":"date-time"}}},"Registration":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"company_name":{"type":"string","nullable":true},"service_interest":{"type":"string","nullable":true},"status":{"type":"string"},"pipeline_stage":{"type":"string","nullable":true},"source":{"type":"string"},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"}},"description":"Read counterpart of POST /registrations. Only visible to the organization-scoped key that submitted it (via submitted_via_organization_id) — a global/internal key sees any registration."},"Payment":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"client_id":{"type":"string","format":"uuid","nullable":true},"invoice_id":{"type":"string","format":"uuid","nullable":true},"amount":{"type":"number"},"currency":{"type":"string"},"status":{"type":"string"},"payment_method":{"type":"string","nullable":true},"payment_reference":{"type":"string","nullable":true},"initiated_at":{"type":"string","format":"date-time","nullable":true},"completed_at":{"type":"string","format":"date-time","nullable":true},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"}},"description":"PayNow webhook metadata and WhatsApp channel linkage columns are deliberately excluded from this scope."},"Document":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"organization_id":{"type":"string","format":"uuid","nullable":true},"entity_type":{"type":"string","example":"invoice"},"entity_id":{"type":"string","format":"uuid"},"document_type":{"type":"string","example":"invoice_v1"},"title":{"type":"string"},"storage_bucket":{"type":"string"},"storage_path":{"type":"string"},"mime_type":{"type":"string","nullable":true},"size_bytes":{"type":"integer","nullable":true},"version":{"type":"integer"},"supersedes_id":{"type":"string","format":"uuid","nullable":true},"source":{"type":"string","enum":["uploaded","generated"]},"generated_from_template_id":{"type":"string","format":"uuid","nullable":true},"created_at":{"type":"string","format":"date-time"}},"description":"storage_path is never a public URL — use GET /documents/{id}/download for a short-lived (<=15 min) signed link, audited on every issue."},"CreateUploadIntentRequest":{"type":"object","required":["entityType","entityId","documentType","title"],"properties":{"entityType":{"type":"string","example":"invoice"},"entityId":{"type":"string","format":"uuid"},"documentType":{"type":"string","example":"signed_engagement_letter"},"title":{"type":"string"},"mimeType":{"type":"string","nullable":true},"fileExtension":{"type":"string","default":"pdf","example":"pdf"}}},"UploadIntentResponse":{"type":"object","properties":{"id":{"type":"string","format":"uuid","description":"The new ici_documents row id (placeholder — size_bytes/mime_type are null until confirmed)."},"uploadUrl":{"type":"string","format":"uri","description":"PUT the file bytes directly to this Supabase Storage signed upload URL."},"uploadToken":{"type":"string"},"path":{"type":"string"}}},"GenerateDocumentRequest":{"type":"object","required":["templateKey","entityType","entityId"],"properties":{"templateKey":{"type":"string","example":"invoice_v1"},"entityType":{"type":"string","enum":["invoice","registration","crm_lead"]},"entityId":{"type":"string","format":"uuid"},"data":{"type":"object","description":"Extra template variables merged over the entity's resolved data.","nullable":true}}}},"responses":{"Unauthorized":{"description":"Missing, malformed, invalid, or revoked API key.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Forbidden":{"description":"The key's scopes don't include the scope this route requires.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"NotFound":{"description":"Resource doesn't exist, or exists but isn't visible to this key's scope.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"ValidationError":{"description":"Request failed Zod validation; see error.issues.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"RateLimited":{"description":"Exceeded rate_limit_per_minute for this key; see Retry-After header.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"paths":{"/partner/catalogue":{"get":{"tags":["Partner orders"],"summary":"Your wholesale catalogue","description":"Everything Infoden sells, with the retail price and YOUR price. `data`: company-registration packages and add-ons (special price, else retail less your tier's discount), ordered with `package`. `services`: every other service (annual returns, CR forms, tax clearance, VAT, PAYE, trademarks, fiscalisation, trusts, PRAZ/NSSA...), retail less your tier's discount, ordered with `services`; `needs_quote: true` items (\"from\" prices) are charged only once Infoden confirms the price (order.priced). Scope catalogue:read. Partner keys only.","parameters":[{"name":"country","in":"query","schema":{"type":"string","enum":["zimbabwe","south_africa","dubai"]}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/CatalogueItem"}}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/orders":{"get":{"tags":["Partner orders"],"summary":"List your orders","description":"Scope orders:read.","parameters":[{"name":"limit","in":"query","schema":{"type":"integer","default":25,"maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer","default":0}},{"name":"reference","in":"query","schema":{"type":"string"},"description":"Your own reference."}],"responses":{"200":{"description":"OK"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}},"post":{"tags":["Partner orders"],"summary":"Place an order (any service)","description":"Orders a company registration (`package` + `details.proposed_names`) or any other services (`services: [{code, qty}]`, optional `company_id` of one of your orders' companies and `details.company_name` / `details.notes`) for your client. Send one or the other. Charged at your price: from your prepaid wallet, or on account if Infoden approved invoicing for you. A services order containing a \"from\" price is placed without charge and priced by Infoden (order.priced). Service orders then move submitted -> accepted -> in_progress -> completed (order.status_changed, order.completed). Work starts immediately. Infoden never contacts your client; you get every update by webhook (order.*, stage.*, names.rejected, document.added) and in your partner dashboard. Send an Idempotency-Key header (or idempotency_key) so a retry never orders twice: the same key with the same body returns the first order (200, idempotent_replay: true); the same key with a different body is refused with 409 idempotency_conflict. With a test key the order is a sandbox order (see x-partner-test-mode). Infoden's invoices and receipts to you carry Infoden's branding: they are your bill, not documents for your client. Scope orders:write.","parameters":[{"name":"Idempotency-Key","in":"header","schema":{"type":"string","maxLength":120}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OrderRequest"}}}},"responses":{"200":{"description":"Same Idempotency-Key as an earlier order: that order is returned (idempotent_replay: true)."},"201":{"description":"Order placed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Order"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"402":{"description":"insufficient_funds (top up your wallet) or credit_limit_reached."},"403":{"$ref":"#/components/responses/Forbidden"},"409":{"description":"idempotency_conflict: this Idempotency-Key was already used for a different order."},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/orders/{id}":{"get":{"tags":["Partner orders"],"summary":"Order status, stages and documents","description":"Scope orders:read.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Order"}}}},"404":{"$ref":"#/components/responses/NotFound"}}}},"/orders/{id}/names":{"post":{"tags":["Partner orders"],"summary":"Send more company names","description":"After names.rejected. Scope orders:write.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["names"],"properties":{"names":{"type":"array","items":{"type":"string"},"minItems":1,"maxItems":10},"message":{"type":"string"}}}}}},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Order"}}}},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/orders/{id}/simulate":{"post":{"tags":["Partner orders"],"summary":"Move a test order along (test keys only)","description":"Sandbox only: advance completes the current stage and starts the next (order.registered and order.completed at the end); reject_names marks the name stage not approved (names.rejected; then send new names); action_needed and add_document send those events. Live keys get 403. Scope orders:write.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["action"],"properties":{"action":{"type":"string","enum":["advance","reject_names","action_needed","add_document"]}}}}}},"responses":{"200":{"description":"The test order after the step","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Order"}}}},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/orders/{id}/documents":{"post":{"tags":["Partner orders"],"summary":"Send a document for the order","description":"PDF, JPEG or PNG up to 10 MB, base64. Scope orders:write.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["name","content_type","content_base64"],"properties":{"name":{"type":"string"},"content_type":{"type":"string","enum":["application/pdf","image/jpeg","image/png"]},"content_base64":{"type":"string"},"note":{"type":"string"}}}}}},"responses":{"201":{"description":"Received"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/orders/{id}/documents/{document_id}":{"get":{"tags":["Partner orders"],"summary":"Download link for a document","description":"A signed link valid for 5 minutes. Scope orders:read.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"document_id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/wallet":{"get":{"tags":["Partner orders"],"summary":"Wallet balance, ledger and open invoices","description":"Scope wallet:read.","responses":{"200":{"description":"OK"}}}},"/health":{"get":{"summary":"Health check","security":[],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string"},"version":{"type":"string"}}}}}}}}},"/openapi.json":{"get":{"summary":"This OpenAPI document","security":[],"responses":{"200":{"description":"OK"}}}},"/companies":{"get":{"summary":"List companies","description":"Requires scope `companies:read`. Scoped keys only see companies belonging to their organization.","parameters":[{"name":"search","in":"query","schema":{"type":"string"},"description":"Filters by company_name (case-insensitive substring)."},{"name":"jurisdiction","in":"query","schema":{"type":"string"},"description":"Jurisdiction code or name, e.g. 'ZW', 'zimbabwe' (ICI Phase 5)."},{"name":"limit","in":"query","schema":{"type":"integer","default":20,"maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer","default":0}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Company"}},"total":{"type":"integer"},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/companies/{id}":{"get":{"summary":"Get a company","description":"Requires scope `companies:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Company"}}}},"404":{"$ref":"#/components/responses/NotFound"}}}},"/companies/{id}/people":{"get":{"summary":"Get a company's structured officers (directors/shareholders/secretary)","description":"Requires scope `companies:read`. Structured replacement for the raw directors/shareholders/secretary JSON that the Company schema deliberately excludes — sourced from the company_people/people identity graph tables.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"company_id":{"type":"string","format":"uuid"},"people":{"type":"array","items":{"$ref":"#/components/schemas/CompanyPerson"}}}}}}},"404":{"$ref":"#/components/responses/NotFound"}}}},"/invoices":{"get":{"summary":"List invoices","description":"Requires scope `invoices:read`. Scoped keys see invoices billed to any client_id in their organization, or to any company their organization owns.","parameters":[{"name":"status","in":"query","schema":{"type":"string"}},{"name":"limit","in":"query","schema":{"type":"integer","default":20,"maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer","default":0}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Invoice"}},"total":{"type":"integer"},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}}}}},"/invoices/{id}":{"get":{"summary":"Get an invoice, including line items","description":"Requires scope `invoices:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Invoice"}}}},"404":{"$ref":"#/components/responses/NotFound"}}}},"/compliance/deadlines":{"get":{"summary":"List upcoming/past compliance deadlines","description":"Requires scope `compliance:read`. Primary source is service_periods (real per-instance due dates); client_services/tax_services rows are included only as a fallback for legacy data never linked to a subscription. tax_services rows now carry company_id and are included under a companyId filter when they have one (see ICI_PHASE1_5.md → Assumptions).","parameters":[{"name":"from","in":"query","schema":{"type":"string","format":"date"}},{"name":"to","in":"query","schema":{"type":"string","format":"date"}},{"name":"companyId","in":"query","schema":{"type":"string","format":"uuid"}},{"name":"jurisdiction","in":"query","schema":{"type":"string"},"description":"Jurisdiction code or name (ICI Phase 5). Rows with no company (e.g. IP applications) are excluded when set."},{"name":"limit","in":"query","schema":{"type":"integer","default":50,"maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer","default":0}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Deadline"}},"total":{"type":"integer"},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}}}}},"/jurisdictions":{"get":{"summary":"List jurisdictions Infoden operates in","description":"Requires scope `catalogue:read`. Public offering data, same for every caller regardless of organization.","parameters":[{"name":"activeOnly","in":"query","schema":{"type":"boolean","default":true}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Jurisdiction"}}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/usage":{"get":{"summary":"Org-scoped usage totals against the current plan (ICI Phase 5)","description":"Requires scope `usage:read`. Requires an organization-scoped key (or session) — an unscoped/internal key has no single organization to report against and gets a 500. Sourced from the daily ici_usage_daily rollup, not live-computed — figures are as fresh as the last usage-rollup run (once daily). period_start is the organization's current billing-period start once it has a plan subscription, else the calendar month start.","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"organization_id":{"type":"string","format":"uuid"},"period_start":{"type":"string","format":"date"},"today":{"type":"string","format":"date"},"today_usage":{"type":"object","additionalProperties":{"type":"integer"}},"period_to_date_usage":{"type":"object","additionalProperties":{"type":"integer"}},"plan":{"type":"object","properties":{"code":{"type":"string"},"name":{"type":"string"}}},"request_limit":{"type":"integer","nullable":true,"description":"null = unlimited"},"requests_used":{"type":"integer","description":"api_requests + mcp_tool_calls this period"},"requests_remaining":{"type":"integer","nullable":true}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/plans":{"get":{"summary":"List the ICI API plan catalogue (ICI Phase 5)","description":"Requires scope `usage:read`. Public pricing/limits data, same for every caller regardless of organization.","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object","properties":{"code":{"type":"string"},"name":{"type":"string"},"price_monthly":{"type":"number"},"currency":{"type":"string"},"monthly_request_limit":{"type":"integer","nullable":true},"overage_price_per_request":{"type":"number"},"description":{"type":"string","nullable":true},"features":{"type":"array","items":{"type":"string"}}}}}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/billing/subscription":{"get":{"summary":"The calling organization's current plan + billing period (ICI Phase 5)","description":"Requires scope `usage:read`. Requires an organization-scoped key/session. An org never assigned a plan is implicitly on 'free'.","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"organization_id":{"type":"string","format":"uuid"},"plan":{"type":"object","properties":{"code":{"type":"string"},"name":{"type":"string"}}},"status":{"type":"string","enum":["active","past_due"]},"current_period_start":{"type":"string","format":"date","nullable":true},"current_period_end":{"type":"string","format":"date","nullable":true}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/jurisdictions/{code}/services":{"get":{"summary":"List the service catalogue for one jurisdiction","description":"Requires scope `catalogue:read`. Includes that jurisdiction's own services plus jurisdiction-agnostic ones (add-ons, bundles).","parameters":[{"name":"code","in":"path","required":true,"schema":{"type":"string"},"example":"ZW"},{"name":"category","in":"query","schema":{"type":"string"}},{"name":"activeOnly","in":"query","schema":{"type":"boolean","default":true}},{"name":"limit","in":"query","schema":{"type":"integer","default":20,"maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer","default":0}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/ServiceCatalogueItem"}},"total":{"type":"integer"},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/registrations":{"post":{"summary":"Submit a company-registration intent","description":"Requires scope `registrations:write`. Does NOT create a company — lands as a crm_leads row (source='api') in the same human review queue the WhatsApp and web funnels use. Nothing is auto-approved.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RegistrationIntentRequest"}}}},"responses":{"201":{"description":"Received","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RegistrationIntentResponse"}}}},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/registrations/{id}":{"get":{"summary":"Get a registration intent's current status","description":"Requires scope `registrations:read`. Returns 404 for a registration that exists but was submitted via a different organization's key (never distinguishes 404 from 403).","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Registration"}}}},"404":{"$ref":"#/components/responses/NotFound"}}}},"/payments":{"get":{"summary":"List payments","description":"Requires scope `payments:read`. Scoped keys see payments against any client_id in their organization, or billed via an invoice to a company their organization owns.","parameters":[{"name":"status","in":"query","schema":{"type":"string"}},{"name":"limit","in":"query","schema":{"type":"integer","default":20,"maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer","default":0}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Payment"}},"total":{"type":"integer"},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/payments/{id}":{"get":{"summary":"Get a payment","description":"Requires scope `payments:read`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Payment"}}}},"404":{"$ref":"#/components/responses/NotFound"}}}},"/documents":{"get":{"summary":"List documents in the registry","description":"Requires scope `documents:read`. Excludes soft-deleted rows. Scoped keys see only their organization's documents.","parameters":[{"name":"entityType","in":"query","schema":{"type":"string"},"example":"invoice"},{"name":"entityId","in":"query","schema":{"type":"string","format":"uuid"}},{"name":"documentType","in":"query","schema":{"type":"string"}},{"name":"limit","in":"query","schema":{"type":"integer","default":20,"maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer","default":0}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Document"}},"total":{"type":"integer"},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}}}}},"/documents/{id}":{"get":{"summary":"Get a document's registry metadata","description":"Requires scope `documents:read`. Does not return file bytes — use the /download route for a signed URL.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Document"}}}},"404":{"$ref":"#/components/responses/NotFound"}}}},"/documents/{id}/download":{"get":{"summary":"Redirect to a short-lived signed download URL","description":"Requires scope `documents:read`. Responds 302 with a `Location` header pointing at a Supabase Storage signed URL valid for 15 minutes. Every download is audited via the standard ici_api_audit_log row for this request.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"302":{"description":"Redirect to the signed URL"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/documents/upload-intent":{"post":{"summary":"Begin a two-step upload: get a signed Storage upload URL","description":"Requires scope `documents:write`. No multipart passes through this gateway — the client PUTs the file directly to the returned Supabase Storage signed URL, then calls POST /documents/{id}/confirm.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateUploadIntentRequest"}}}},"responses":{"201":{"description":"Created","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UploadIntentResponse"}}}},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/documents/{id}/confirm":{"post":{"summary":"Confirm a completed upload and finalize its registry metadata","description":"Requires scope `documents:write`. Reads the real size_bytes/mime_type back from Storage and emits a `document.uploaded` event.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Document"}}}},"404":{"$ref":"#/components/responses/NotFound"}}}},"/documents/generate":{"post":{"summary":"Server-side generate a document from a registered template","description":"Requires scope `documents:write`. Renders a versioned document (currently HTML, not PDF — see ICI_PHASE3.md for the renderer decision) from the named template and the given entity's data, resolved only through this API's own read-scoped service functions so a generated document can never surface a field its read scope would exclude. Emits `document.generated`.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/GenerateDocumentRequest"}}}},"responses":{"201":{"description":"Created","content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"download_url":{"type":"string","format":"uri","nullable":true}}}}}},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/webhooks":{"get":{"summary":"List this organization's webhook endpoints","description":"Requires scope `webhooks:manage`. Requires an organization-scoped key — a global/internal key has no single organization to list endpoints for. Never returns `secret`.","parameters":[{"name":"limit","in":"query","schema":{"type":"integer","default":20,"maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer","default":0}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/WebhookEndpoint"}},"total":{"type":"integer"},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}},"403":{"$ref":"#/components/responses/Forbidden"}}},"post":{"summary":"Register a webhook endpoint","description":"Requires scope `webhooks:manage`. The response is the ONLY time `secret` is ever returned — use it to verify `X-ICI-Signature` on every delivery (see the top-level webhook guide).","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateWebhookRequest"}}}},"responses":{"201":{"description":"Created","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WebhookEndpoint"}}}},"422":{"$ref":"#/components/responses/ValidationError"}}}},"/webhooks/{id}":{"delete":{"summary":"Remove a webhook endpoint","description":"Requires scope `webhooks:manage`.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Deleted"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/webhooks/{id}/test":{"post":{"summary":"Send a signed `webhook.ping` test event to this endpoint","description":"Requires scope `webhooks:manage`. Queued immediately; check the admin dashboard or your own endpoint logs for the delivery outcome.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"202":{"description":"Queued","content":{"application/json":{"schema":{"type":"object","properties":{"event_id":{"type":"string","format":"uuid"},"status":{"type":"string","enum":["queued"]}}}}}},"404":{"$ref":"#/components/responses/NotFound"}}}},"/events":{"get":{"summary":"List recent events","description":"Requires scope `events:read`. Org-scoped keys see only their organization's events.","parameters":[{"name":"type","in":"query","schema":{"type":"string"},"description":"Filter by exact event_type, e.g. invoice.paid."},{"name":"from","in":"query","schema":{"type":"string","format":"date-time"}},{"name":"to","in":"query","schema":{"type":"string","format":"date-time"}},{"name":"limit","in":"query","schema":{"type":"integer","default":50,"maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer","default":0}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Event"}},"total":{"type":"integer"},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}}}}}}}