> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sync2books.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create expenses and queue for sync

> Always takes an array, even for a single expense.



## OpenAPI

````yaml /openapi/accounting.json post /expenses/{connectionId}
openapi: 3.1.0
info:
  title: Sync2Books Accounting API
  version: 1.0.0
  description: >-
    Write categorized expenses, bills, invoices, and payments to your customers'
    accounting systems (QuickBooks Online, Xero, Sage, Dynamics 365 Business
    Central, Odoo) through one API.


    This is a **separate product** from the [Sync2Books Compliance API
    (eTIMS)](/etims-overview) — use this one to sync bookkeeping data to an
    accounting system; use that one for KRA tax compliance in Kenya. A company
    can use either, both, or neither.


    Writes are **asynchronous**: most create endpoints queue the record and
    return a `syncBatchId` you confirm via the [Sync](#tag/Sync) endpoints — see
    [The sync model](/concepts/sync-model).
servers:
  - url: https://api.sync2books.com
    description: Production
  - url: https://sandbox-api.sync2books.com
    description: Sandbox (coming soon)
security:
  - ApiKeyAuth: []
tags:
  - name: Companies
    description: Your customers — the entities you sync data for.
  - name: Expenses
    description: Categorized expenses, receipts, and payments.
  - name: Bills
    description: Accounts-payable documents (money you owe suppliers).
  - name: Invoices
    description: Accounts-receivable documents (money customers owe you).
  - name: Bill Payments
    description: Payments applied against one or more bills.
  - name: Attachments
    description: Receipts and supporting documents on a synced transaction.
  - name: Sync
    description: Track and retry the asynchronous batches every write creates.
paths:
  /expenses/{connectionId}:
    post:
      tags:
        - Expenses
      summary: Create expenses and queue for sync
      description: Always takes an array, even for a single expense.
      parameters:
        - $ref: '#/components/parameters/ConnectionId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: array
              minItems: 1
              items:
                $ref: '#/components/schemas/CreateExpenseRequest'
      responses:
        '201':
          description: Queued
          content:
            application/json:
              schema:
                type: object
                properties:
                  syncBatchId:
                    type: string
                    format: uuid
                  totalExpenses:
                    type: integer
components:
  parameters:
    ConnectionId:
      name: connectionId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: The connection to the accounting system to write through.
  schemas:
    CreateExpenseRequest:
      type: object
      required:
        - id
        - type
        - issueDate
        - currency
        - currencyRate
        - merchantName
        - lines
      properties:
        id:
          type: string
          description: Your own identifier for this expense.
        type:
          type: string
          example: Payment
        issueDate:
          type: string
          format: date-time
        currency:
          type: string
          example: USD
        currencyRate:
          type: number
        contactRef:
          type: object
          properties:
            id:
              type: string
            type:
              type: string
        bankAccountRef:
          $ref: '#/components/schemas/Ref'
        merchantName:
          type: string
        lines:
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/ExpenseLineItem'
        notes:
          type: string
        postAsDraft:
          type: boolean
          default: false
    Ref:
      type: object
      required:
        - id
      properties:
        id:
          type: string
        name:
          type: string
    ExpenseLineItem:
      type: object
      required:
        - netAmount
        - taxAmount
        - taxRateRef
        - accountRef
      properties:
        netAmount:
          $ref: '#/components/schemas/Money'
        taxAmount:
          $ref: '#/components/schemas/Money'
        taxRateRef:
          $ref: '#/components/schemas/Ref'
        accountRef:
          $ref: '#/components/schemas/Ref'
        trackingRefs:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              dataType:
                type: string
        invoiceTo:
          type: object
          properties:
            id:
              type: string
            type:
              type: string
    Money:
      type: number
      description: Decimal amount in the document's `currency`.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: >-
        Your application's API key (`sk_development_…` or `sk_production_…`). An
        optional `X-Signature` / `X-Timestamp` HMAC pair may additionally be
        sent for stronger security — see
        [Authentication](/concepts/authentication).

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.