{"openapi":"3.1.0","info":{"title":"POST /api/v1/businesses","version":"1.0.0","description":"Create business"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/businesses":{"post":{"tags":["businesses"],"summary":"Create business","description":"Create a new business entity with optional integrations.","operationId":"create_business_api_v1_businesses_post","parameters":[{"name":"authorization","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Authorization"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/BusinessCreateRequest"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BusinessResponse"}}}},"400":{"description":"Bad Request - Invalid input","content":{"application/json":{"example":{"detail":"Invalid request parameters"}}}},"401":{"description":"Unauthorized - Authentication required","content":{"application/json":{"example":{"detail":"Not authenticated"}}}},"403":{"description":"Forbidden - Insufficient permissions","content":{"application/json":{"example":{"detail":"Not enough permissions"}}}},"409":{"description":"Conflict - Resource already exists","content":{"application/json":{"example":{"detail":"Resource already exists"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"AccountSchema":{"properties":{"plaid_account_id":{"type":"string","title":"Plaid Account Id","description":"Plaid's unique account ID."},"ledger_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Ledger Id","description":"Linked ledger UUID in chart of accounts."},"teal_source_account_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Teal Source Account Id","description":"Teal accounting system source account ID."},"balance":{"$ref":"#/components/schemas/BalanceSchema","description":"Current account balances."},"mask":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Mask","description":"Last 4 digits of account number (e.g., '1234')."},"name":{"type":"string","title":"Name","description":"Account name from the bank."},"official_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Official Name","description":"Official account name from the bank."},"subtype":{"type":"string","title":"Subtype","description":"Account subtype (e.g., 'checking', 'savings', 'credit card')."},"type":{"type":"string","title":"Type","description":"Account type: depository, credit, loan, investment."},"last_synced":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"title":"Last Synced","description":"When transactions were last synced."},"business_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Business Id","description":"Business UUID."},"created_at":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"title":"Created At","description":"When account was linked."},"error_code":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Error Code","description":"Plaid error code if sync failed."},"error":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Error","description":"Error details if sync failed."},"is_linked":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Is Linked","description":"Whether account is saved in our database."},"is_synced_to_teal":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Is Synced To Teal","description":"Whether account is synced to Teal accounting."}},"additionalProperties":true,"type":"object","required":["plaid_account_id","balance","name","subtype","type"],"title":"AccountSchema","description":"Schema for a bank account connected via Plaid.\n\nRepresents a single bank account (checking, savings, credit card, etc.)\nthat is linked to the business through a Plaid connection.\n\n**Account Types:**\n- `depository`: Checking, savings accounts\n- `credit`: Credit cards\n- `loan`: Loans, mortgages\n- `investment`: Brokerage, retirement accounts","example":{"balance":{"available":1523450,"current":1548200,"iso_currency_code":"USD"},"business_id":"019ab37c-bus1-7000-8000-000000000001","is_linked":true,"is_synced_to_teal":true,"last_synced":"2024-01-15T14:00:00Z","ledger_id":"019ab37c-led1-7000-8000-000000000001","mask":"1234","name":"Chase Business Checking","official_name":"CHASE BUSINESS COMPLETE CHECKING","plaid_account_id":"plaid_acc_abc123","subtype":"checking","teal_source_account_id":"teal_src_xyz789","type":"depository"}},"BalanceSchema":{"properties":{"available":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Available","description":"Available balance in cents (what can be spent now)."},"current":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Current","description":"Current balance in cents (includes pending transactions)."},"iso_currency_code":{"type":"string","title":"Iso Currency Code","description":"ISO 4217 currency code (e.g., 'USD')."},"limit":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Limit","description":"Credit limit in cents (for credit cards)."},"unofficial_currency_code":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Unofficial Currency Code","description":"Unofficial currency code if ISO code unavailable."},"is_available":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Is Available","description":"Whether available balance is reported (0 or 1)."}},"additionalProperties":true,"type":"object","required":["iso_currency_code"],"title":"BalanceSchema","description":"Schema for a bank account balance from Plaid.\n\nAmounts are in cents (e.g., 150000 = $1,500.00).","example":{"available":1523450,"current":1548200,"is_available":1,"iso_currency_code":"USD"}},"BusinessCreateRequest":{"properties":{"name":{"type":"string","title":"Name","description":"Business display name."},"default_currency":{"type":"string","title":"Default Currency","description":"Default currency for the business (USD, CAD, AUD, EUR, or GBP).","default":"USD"},"tax_year_end_month":{"type":"integer","maximum":12.0,"minimum":1.0,"title":"Tax Year End Month","description":"Month when the tax/fiscal year ends (1-12). Default 12 = calendar year.","default":12},"mailbox":{"type":"string","title":"Mailbox","description":"Unique email prefix for bill forwarding."},"user_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"User Id","description":"UUID of the user who will own this business. Optional for admin-created businesses."},"create_teal_instance":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Create Teal Instance","description":"If true, creates a new Teal accounting instance. Default false since DayZero local engine is now the default.","default":false},"teal_instance":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Teal Instance","description":"Existing Teal instance ID to use (if not creating new)."},"coa_template_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Coa Template Id","description":"Pre-built chart of accounts template ID. Mutually exclusive with custom_coa_template."},"custom_coa_template":{"anyOf":[{"$ref":"#/components/schemas/CustomCoaTemplate"},{"type":"null"}],"description":"Custom chart of accounts definition. Mutually exclusive with coa_template_id."},"entries_start":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Entries Start","description":"Date from which to start importing transactions (YYYY-MM-DD)."},"firm_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Firm Id","description":"Advisory firm UUID to link this business to."},"stripe_account_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Stripe Account Id","description":"Stripe Connect account ID."},"stripe_subscription_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Stripe Subscription Id","description":"Stripe subscription ID for billing."},"stripe_customer_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Stripe Customer Id","description":"Stripe customer ID (e.g., cus_xxx)."},"subscription_items":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Subscription Items","description":"Stripe subscription items/products linked to this business."},"accounting_engine_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Accounting Engine Type","description":"Accounting engine: 'local' (DayZero, default), 'teal', or null (inherit from firm)."}},"additionalProperties":false,"type":"object","required":["name","mailbox"],"title":"BusinessCreateRequest","description":"Request schema for creating a new business.\n\nCreates a business entity with an accounting system (Teal instance)\nand associates it with a user as the owner.\n\n**Chart of Accounts Options:**\n- Use `coa_template_id` for pre-built templates\n- Use `custom_coa_template` for custom chart of accounts\n- These options are mutually exclusive","example":{"coa_template_id":"standard_accrual","create_teal_instance":true,"entries_start":"2024-01-01","mailbox":"acme","name":"Acme Corporation","user_id":"019ab37c-user-7000-8000-000000000001"}},"BusinessResponse":{"properties":{"id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Id","description":"Business UUID."},"firm_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Firm Id","description":"Advisory firm UUID this business belongs to."},"mailbox":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Mailbox","description":"Email prefix for bill forwarding."},"name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Name","description":"Business name."},"logo_url":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Logo Url","description":"URL to business logo/avatar image."},"default_currency":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Default Currency","description":"Default currency for the business (USD, CAD, AUD, EUR, or GBP)."},"tax_year_end_month":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Tax Year End Month","description":"Month when the tax/fiscal year ends (1-12). 12 = calendar year."},"tax_year_display":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Tax Year Display","description":"Human-readable tax year description (e.g., 'Calendar Year (Jan-Dec)')."},"created_at":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"title":"Created At","description":"Creation timestamp."},"updated_at":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"title":"Updated At","description":"Last update timestamp."},"teal_instance_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Teal Instance Id","description":"Teal instance ID (API format)."},"teal_instance":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Teal Instance","description":"Teal database ID."},"entries_start":{"anyOf":[{"type":"string","format":"date-time"},{"type":"null"}],"title":"Entries Start","description":"Start date for transaction imports."},"stripe_account_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Stripe Account Id","description":"Connected Stripe account ID."},"stripe_subscription_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Stripe Subscription Id","description":"Stripe subscription ID."},"stripe_customer_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Stripe Customer Id","description":"Stripe customer ID."},"subscription_items":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Subscription Items","description":"Stripe subscription items/products linked to this business."},"shopify_shop_domain":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Shopify Shop Domain","description":"Connected Shopify domain."},"shopify_access_token_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Shopify Access Token Id","description":"Shopify token UUID."},"ramp_connection_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Ramp Connection Id","description":"Ramp connection UUID."},"square_connection_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Square Connection Id","description":"Square connection UUID."},"finch_connection_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Finch Connection Id","description":"Finch payroll connection UUID."},"hubspot_connection_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Hubspot Connection Id","description":"HubSpot connection UUID."},"plaid_connections":{"anyOf":[{"items":{"$ref":"#/components/schemas/PlaidConnectionSchema"},"type":"array"},{"type":"null"}],"title":"Plaid Connections","description":"Connected bank accounts via Plaid."},"slack_connected":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Slack Connected","description":"Whether a Slack webhook URL is configured."},"sync":{"anyOf":[{"$ref":"#/components/schemas/SyncStatus"},{"type":"null"}],"description":"Teal sync status."},"inventory_mode":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Inventory Mode","description":"Inventory module flavor: 'cpg' or 'finished_goods'."}},"additionalProperties":true,"type":"object","title":"BusinessResponse","description":"Response schema for a business.\n\nContains all business details including connected integrations\nand sync status with the accounting system.","example":{"created_at":"2024-01-10T10:30:00Z","entries_start":"2024-01-01T00:00:00Z","firm_id":"019ab37c-firm-7000-8000-000000000001","id":"019ab37c-bus1-7000-8000-000000000001","mailbox":"acme","name":"Acme Corporation","plaid_connections":[],"shopify_shop_domain":"acme-store.myshopify.com","stripe_account_id":"acct_abc123","sync":{"last_synced":"2024-01-15T14:00:00Z","status":"completed"},"teal_instance_id":"teal_inst_abc123","updated_at":"2024-01-15T14:00:00Z"}},"CustomCoaLedger":{"properties":{"name":{"type":"string","minLength":1,"title":"Name","description":"Ledger name"},"type":{"type":"string","title":"Type","description":"Ledger type: asset, liability, equity, revenue, expense"},"sub_type":{"type":"string","title":"Sub Type","description":"Ledger sub-type: current_assets, non-current_assets, transfers_between_accounts, uncategorized_assets, current_liabilities, non-current_liabilities, equity, operating_revenues, other_income, cost_of_goods_sold, operating_expenses, other_expenses"},"sort_code":{"type":"string","maxLength":20,"title":"Sort Code","description":"Numeric sort code for ordering (digits only, max 20 chars)"},"debit_credit":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Debit Credit","description":"Debit/credit behavior: debit, credit. Optional - Teal auto-determines based on ledger type."},"report_cash_flow":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Report Cash Flow","description":"Include in cash flow reports. Optional."},"editable":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Editable","description":"Whether line entries can be manually added or removed","default":true},"description":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Description","description":"Ledger description"},"financial_account_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Financial Account Type","description":"Financial account type for Templated Mode. Options: bank_account, credit_card, payments, payroll, loan, prepaid_card, accounts_receivable, accounts_payable"}},"type":"object","required":["name","type","sub_type","sort_code"],"title":"CustomCoaLedger","description":"Schema for a ledger definition in a custom COA template.\n\nPer the Teal API (https://docs.teal.dev/api-reference/instances/create-an-instance),\nonly name, type, sub_type, and sort_code are required. Teal automatically determines\ndebit_credit based on the ledger type."},"CustomCoaTemplate":{"properties":{"ledgers":{"items":{"$ref":"#/components/schemas/CustomCoaLedger"},"type":"array","minItems":1,"title":"Ledgers","description":"List of ledger definitions for the custom COA"}},"type":"object","required":["ledgers"],"title":"CustomCoaTemplate","description":"Schema for a custom COA template that defines all ledgers."},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"PlaidConnectionSchema":{"properties":{"id":{"type":"string","title":"Id","description":"Plaid Item UUID."},"created_at":{"type":"string","format":"date-time","title":"Created At","description":"When connection was established."},"updated_at":{"type":"string","format":"date-time","title":"Updated At","description":"Last update timestamp."},"item_id":{"type":"string","title":"Item Id","description":"Plaid Item ID."},"institution_id":{"type":"string","title":"Institution Id","description":"Plaid institution ID (e.g., 'ins_3')."},"institution_name":{"type":"string","title":"Institution Name","description":"Bank/institution name."},"accounts":{"anyOf":[{"items":{"$ref":"#/components/schemas/AccountSchema"},"type":"array"},{"type":"null"}],"title":"Accounts","description":"Bank accounts associated with this connection.","default":[]},"business_id":{"type":"string","title":"Business Id","description":"Business UUID."},"sync_status":{"type":"string","title":"Sync Status","description":"Current sync status."},"error_code":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Error Code","description":"Plaid error code if sync failed."}},"additionalProperties":true,"type":"object","required":["id","created_at","updated_at","item_id","institution_id","institution_name","business_id","sync_status"],"title":"PlaidConnectionSchema","description":"Response schema for a Plaid bank connection.\n\nRepresents a linked bank institution with its associated accounts.\nCreated when a user connects a bank via the Plaid Link flow.\n\n**Sync Status Values:**\n- `syncing`: Initial sync in progress\n- `synced`: Fully synced and up to date\n- `error`: Sync failed (check error_code)\n- `disconnected`: Connection needs re-authentication","example":{"accounts":[{"id":"019ab37c-acc1-7000-8000-000000000001","mask":"1234","name":"Chase Business Checking","subtype":"checking","type":"depository"}],"business_id":"019ab37c-bus1-7000-8000-000000000001","created_at":"2024-01-10T10:30:00Z","id":"019ab37c-plaid-7000-8000-000000000001","institution_id":"ins_3","institution_name":"Chase","item_id":"plaid_item_abc123","sync_status":"synced","updated_at":"2024-01-15T14:00:00Z"}},"SyncStatus":{"properties":{"status":{"type":"string","enum":["syncing","completed","nothing_to_sync"],"title":"Status","description":"Sync status: 'syncing', 'completed', or 'nothing_to_sync'"},"last_synced":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Last Synced","description":"ISO timestamp of last successful sync"},"sync_in_progress":{"type":"boolean","title":"Sync In Progress","description":"Whether a teal-sync task is currently running (from tasks table)","default":false}},"type":"object","required":["status"],"title":"SyncStatus","description":"Sync status for a business."},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"},"input":{"title":"Input"},"ctx":{"type":"object","title":"Context"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}},"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API Token","description":"API token authentication. Format: `Bearer dz_...`"}}},"security":[{"BearerAuth":[]}]}