Codat.Platform.DataStatus (codat v1.0.0)

Copy Markdown View Source

Query and manage data sync status for a company's connections.

Codat caches data pulled from integrations. This module lets you check the freshness of each data type and trigger on-demand refreshes.

Sync Statuses

StatusMeaning
CompleteLast sync succeeded. Data is available.
FetchErrorSync failed. Check the error message.
NotSupportedThis data type is not supported for the integration.
ProcessingQueuedA sync has been queued but not yet started.
ProcessingSync is currently running.
ValidationErrorData failed Codat's validation step.
AuthErrorConnection was deauthorized mid-sync.

Example

{:ok, statuses} = Codat.Platform.DataStatus.get(client, "company-id")

invoices_status = statuses["invoices"]
invoices_status["currentStatus"]   # => "Complete"
invoices_status["lastSuccessfulSync"]  # => "2024-01-15T10:30:00Z"

Summary

Functions

Returns the sync status for all data types for a given company.

Returns the history of pull operations (data syncs) for a company.

Queues an on-demand sync for a specific data type on a company.

Queues an on-demand sync for all data types on a company.

Functions

get(client_or_company_id, id_or_opts \\ [])

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

Returns the sync status for all data types for a given company.

Returns a map keyed by data type name (e.g. "invoices", "bills").

Example

{:ok, statuses} = Codat.Platform.DataStatus.get(client, "company-id")
# => %{"invoices" => %{"currentStatus" => "Complete", ...}, ...}

get_for_type(client_or_company_id, company_or_data_type, data_type_or_opts \\ [])

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

Returns the sync status for a single data type.

Example

{:ok, status} = Codat.Platform.DataStatus.get_for_type(client, "company-id", "invoices")
status["currentStatus"]       # => "Complete"
status["lastSuccessfulSync"]  # => "2024-01-15T10:30:00Z"

get_pull_operation(client_or_company_id, company_or_dataset_id, dataset_or_opts \\ [])

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

Returns a single pull operation by its dataset ID.

Example

{:ok, op} = Codat.Platform.DataStatus.get_pull_operation(client, "company-id", "dataset-id")
op["status"]  # => "Complete"

pull_operations(client_or_company_id, company_id_or_opts \\ [], opts \\ [])

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

Returns the history of pull operations (data syncs) for a company.

Options

  • :page, :page_size — pagination
  • :query — filter operations

Example

{:ok, ops} = Codat.Platform.DataStatus.pull_operations(client, "company-id")

refresh(client_or_company_id, company_or_data_type, data_type_or_opts \\ [])

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

Queues an on-demand sync for a specific data type on a company.

Example

{:ok, _} = Codat.Platform.DataStatus.refresh(client, "company-id", "invoices")

refresh_all(client_or_company_id, id_or_opts \\ [])

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

Queues an on-demand sync for all data types on a company.

Returns immediately. Subscribe to the data.sync.complete webhook to be notified when each data type finishes syncing.

Example

{:ok, _} = Codat.Platform.DataStatus.refresh_all(client, "company-id")