Codat.Expenses.Sync (codat v1.0.0)

Copy Markdown View Source

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)

Summary

Functions

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

Functions

complete(client_or_company_id, company_or_sync_id, sync_or_opts \\ [])

@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(client_or_company_id, company_or_sync_id, sync_or_opts \\ [])

@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(client_or_company_id, company_or_sync_id, sync_or_opts \\ [])

@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(client_or_company_id, company_or_body, body_or_opts \\ %{})

@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(client_or_company_id, company_id_or_opts \\ [], opts \\ [])

@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.