Codat.Platform.Connections (codat v1.0.0)

Copy Markdown View Source

Manage data connections between companies and their accounting/banking platforms.

A connection links a Codat company to a specific data source (e.g., QuickBooks Online, Xero, Sage Intacct). Each company can have multiple connections.

Connection Statuses

StatusDescription
LinkedActive, authorized connection. Data syncs can run.
DeauthorizedUser revoked access. Must re-link to resume syncing.
UnlinkedConnection was manually disconnected from the Codat side.
PendingAuthAuthorization flow started but not yet completed.

Re-authorization

When a connection becomes Deauthorized, redirect the user through the Link flow again. Use get_authorization_url/3 to get the redirect URL. Do not create a new company for re-linking — it may incur additional usage costs.

Example

{:ok, page} = Codat.Platform.Connections.list(client, "company-id")
connections = page.results

linked = Enum.filter(connections, &(&1["status"] == "Linked"))

Summary

Functions

Deletes a data connection, removing it and all synced data.

Fetches a single connection by company ID and connection ID.

Returns the authorization URL for re-linking a deauthorized connection.

Lists all data connections for a company.

Unlinks a connection without deleting it or its data.

Functions

create(client_or_company_id, company_or_platform_key, platform_key_or_opts \\ [])

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

Creates a new data connection for a company.

Parameters

  • platform_key (required) — the integration key (e.g. "gbol" for QuickBooks Online). See Codat integrations docs for all platform keys.

Example

{:ok, conn} = Codat.Platform.Connections.create(client, "company-id", "gbol")
conn["status"]        # => "PendingAuth"
conn["linkUrl"]       # => "https://link.codat.io/..."

delete(client_or_company_id, company_or_conn_id, conn_or_opts \\ [])

@spec delete(Codat.Client.t() | String.t(), String.t(), String.t() | keyword()) ::
  {:ok, nil} | {:error, Codat.Error.t()}

Deletes a data connection, removing it and all synced data.

Use unlink/3 instead if you want to preserve synced data but stop future syncs.

get(client_or_company_id, company_or_conn_id, conn_or_opts \\ [])

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

Fetches a single connection by company ID and connection ID.

Example

{:ok, conn} = Codat.Platform.Connections.get(client, "company-id", "conn-id")
conn["status"]  # => "Linked"
conn["integrationKey"]  # => "gbol"  (QuickBooks Online)

get_authorization_url(client_or_company_id, company_or_conn_id, conn_or_opts \\ [])

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

Returns the authorization URL for re-linking a deauthorized connection.

Example

{:ok, %{"url" => url}} =
  Codat.Platform.Connections.get_authorization_url(client, "company-id", "conn-id")

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 data connections for a company.

Options

  • :page, :page_size — pagination
  • :query — filter by status, e.g. "status=Linked"

Example

{:ok, page} = Codat.Platform.Connections.list(client, "company-id")
{:ok, page} = Codat.Platform.Connections.list("company-id", query: "status=Linked")

unlink(client_or_company_id, company_or_conn_id, conn_or_opts \\ [])

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

Unlinks a connection without deleting it or its data.

Sets the connection status to Unlinked. The company and its historical data are preserved. You can re-link by creating a new connection or redirecting the user through Link.

Example

{:ok, conn} = Codat.Platform.Connections.unlink(client, "company-id", "conn-id")
conn["status"]  # => "Unlinked"