Create Transactions

Create expense transactions and submit them for sync to your customer's accounting software

Overview

When you create an expense transaction, Sync2Books stores it in the database and queues it for sync to the connected accounting system. The actual synchronization happens asynchronously, allowing you to create multiple expenses efficiently.

Prerequisites

Before creating expenses, ensure you have:

  • API Key - Your application's API key

  • Connection ID - A connected accounting system (QuickBooks, Xero, or Sage)

  • Account IDs - Valid account IDs from the accounting system

  • Tax Rate IDs - Valid tax rate IDs (if applicable)

Create a single expense

Endpoint

POST /expenses/{connectionId}

Request Body

Field Descriptions

Field
Type
Required
Description

id

string

Unique identifier for the expense (UUID format recommended)

type

string

Expense type: "Payment" or "DirectCost"

issueDate

string (ISO 8601)

Date when the expense was incurred

currency

string

Three-letter currency code (e.g., "USD", "GBP")

currencyRate

number

Exchange rate (usually 1 for base currency)

merchantName

string

Name of the merchant/vendor

contactRef

object

Reference to a supplier/customer

bankAccountRef

object

Reference to the bank account used

lines

array

Array of expense line items

notes

string

Additional notes about the expense

postAsDraft

boolean

If true, creates as draft in accounting system

Expense Lines

Each expense line item requires:

  • netAmount (number, required): Net amount before tax

  • taxAmount (number, required): Tax amount

  • taxRateRef (object, required): Reference to tax rate

  • accountRef (object, required): Reference to expense account

Optional fields:

  • trackingRefs (array): Tracking categories for reporting

  • invoiceTo (object): Customer to invoice (for billable expenses)

Example: Simple Expense

Response

The syncBatchId is used to track the sync status. See Sync transactions for monitoring sync progress.

Create multiple expenses (batch)

You can create multiple expenses in a single request for better efficiency:

Request

Response

All expenses in the batch are processed together and share the same syncBatchId.

Transaction types

Payment

A standard expense payment. This is the most common transaction type.

DirectCost

A direct cost expense, typically used for cost of goods sold (COGS).

Expense line items

Basic line item

Line item with tracking

Billable expense line item

Data model

Expense Entity

Expense Line

Getting reference IDs

Before creating expenses, you need valid IDs from your accounting system. See Map transactions for details on retrieving account, tax rate, supplier, and customer IDs.

Error handling

Validation errors

If required fields are missing or invalid:

Invalid reference IDs

If a reference ID doesn't exist in the accounting system, the sync will fail. Check the sync batch status for error details.

Best practices

  1. Use UUIDs for expense IDs - Ensures uniqueness across your system

  2. Batch multiple expenses - More efficient than individual requests

  3. Validate data before sending - Ensure all required fields are present

  4. Use company-level defaults - Reduce transaction complexity by setting defaults

  5. Handle errors gracefully - Implement retry logic for transient failures

Last updated