# `Codat.Expenses.Sync`
[🔗](https://github.com/iamkanishka/codat.git/blob/v1.0.0/lib/codat/expenses/expenses.ex#L1)

Manage expense sync sessions.

The Expenses API works via a **sync session** model:
1. `initialize/3` — create a sync to hold transactions
2. Push expense transactions to the sync
3. `complete/3` — finalize and write transactions to the accounting platform
4. Receive `expenses.sync.successful` or `expenses.sync.failed` webhook

## Example

    # 1. Start a sync
    {:ok, sync} = Codat.Expenses.Sync.initialize(client, company_id, %{
      dataType: "expense"
    })
    sync_id = sync["id"]

    # 2. Push transactions into the sync
    {:ok, _} = Codat.Expenses.Transactions.create(client, company_id, sync_id, [%{...}])

    # 3. Complete the sync to write to the accounting platform
    {:ok, _} = Codat.Expenses.Sync.complete(client, company_id, sync_id)

# `complete`

```elixir
@spec complete(Codat.Client.t() | String.t(), String.t(), String.t() | keyword()) ::
  {:ok, map()} | {:error, Codat.Error.t()}
```

Completes (finalizes) an expense sync, triggering the write to the accounting platform.

## Example

    {:ok, _} = Codat.Expenses.Sync.complete(client, company_id, sync_id)

# `get`

```elixir
@spec get(Codat.Client.t() | String.t(), String.t(), String.t() | keyword()) ::
  {:ok, map()} | {:error, Codat.Error.t()}
```

Returns a single sync by ID.

# `get_transaction_updates`

```elixir
@spec get_transaction_updates(
  Codat.Client.t() | String.t(),
  String.t(),
  String.t() | keyword()
) ::
  {:ok, map()} | {:error, Codat.Error.t()}
```

Returns the list of transaction updates from a sync.

# `initialize`

```elixir
@spec initialize(Codat.Client.t() | String.t(), String.t() | map(), map() | keyword()) ::
  {:ok, map()} | {:error, Codat.Error.t()}
```

Initializes a new expense sync session.

## Example

    {:ok, sync} = Codat.Expenses.Sync.initialize(client, company_id, %{
      dataType: "expense"
    })

# `list`

```elixir
@spec list(Codat.Client.t() | String.t(), String.t() | keyword(), keyword()) ::
  {:ok, Codat.Pagination.t()} | {:error, Codat.Error.t()}
```

Lists all expense syncs for a company.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
