Codat.Platform.Files (codat v1.0.0)

Copy Markdown View Source

Upload and retrieve business documents (files) for a company.

The Files API lets you store supporting documents alongside financial data — bank statements, invoices, receipts, tax returns, etc.

Supported File Types

Codat accepts PDFs, images (PNG, JPEG), and Excel files. Each file is associated with a company and optionally tagged with a date range.

Example

# Upload a PDF bank statement
file_data = File.read!("statement.pdf")
{:ok, _} = Codat.Platform.Files.upload(client, "company-id", file_data, "application/pdf")

# List all uploaded files
{:ok, files} = Codat.Platform.Files.list(client, "company-id")

# Download a specific file
{:ok, content} = Codat.Platform.Files.download(client, "company-id", "file-id")

Summary

Functions

download(client_or_company_id, company_or_file_id, file_or_opts \\ [])

@spec download(Codat.Client.t() | String.t(), String.t(), String.t() | keyword()) ::
  {:ok, binary() | map() | list() | nil} | {:error, Codat.Error.t()}

Downloads a file's contents by its file ID.

Returns the raw binary content.

Example

{:ok, binary} = Codat.Platform.Files.download(client, "company-id", "file-id")
File.write!("downloaded.pdf", binary)

download_all(client_or_company_id, id_or_opts \\ [])

@spec download_all(Codat.Client.t() | String.t(), String.t() | keyword()) ::
  {:ok, binary() | map() | list() | nil} | {:error, Codat.Error.t()}

Downloads all files for a company as a ZIP archive.

Example

{:ok, zip_bytes} = Codat.Platform.Files.download_all(client, "company-id")
File.write!("company-docs.zip", zip_bytes)

list(client_or_company_id, id_or_opts \\ [])

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

Lists all files uploaded for a company.

Example

{:ok, files} = Codat.Platform.Files.list(client, "company-id")
# => [%{"fileId" => "...", "fileName" => "statement.pdf", ...}]

upload(client_or_company_id, company_or_data, data_or_content_type, content_type_or_opts, opts \\ [])

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

Uploads a file for a company.

Parameters

  • company_id — the company to attach the file to
  • file_data — binary file contents
  • content_type — MIME type (e.g. "application/pdf", "image/jpeg")

Options

  • :file_name — override the filename (default: "upload")

Example

pdf = File.read!("statement.pdf")
{:ok, _} = Codat.Platform.Files.upload(client, "company-id", pdf, "application/pdf",
  file_name: "jan-2024-statement.pdf"
)