# `Codat.Platform.DataStatus`
[🔗](https://github.com/iamkanishka/codat.git/blob/v1.0.0/lib/codat/platform/data_status.ex#L1)

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

| Status              | Meaning                                              |
|---------------------|------------------------------------------------------|
| `Complete`          | Last sync succeeded. Data is available.              |
| `FetchError`        | Sync failed. Check the error message.                |
| `NotSupported`      | This data type is not supported for the integration. |
| `ProcessingQueued`  | A sync has been queued but not yet started.          |
| `Processing`        | Sync is currently running.                           |
| `ValidationError`   | Data failed Codat's validation step.                 |
| `AuthError`         | Connection 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"

# `get`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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")

---

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