Codat.Accounting.Attachments (codat v1.0.0)

Copy Markdown View Source

Upload and manage file attachments for accounting records.

Supports attaching PDFs and images to invoices, bills, direct costs, direct incomes, transfers, purchase orders, credit notes, and bill credit notes.

Example

pdf_bytes = File.read!("invoice-backup.pdf")

{:ok, _} = Codat.Accounting.Attachments.upload(
  client, company_id, connection_id,
  "invoices", invoice_id,
  pdf_bytes, "application/pdf",
  file_name: "invoice-backup.pdf"
)

Summary

Functions

delete(client_or_company_id, company_or_data_type, data_type_or_record_id, record_or_attachment_id, attachment_or_opts \\ [])

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

Deletes an attachment from a record.

download(client_or_company_id, company_or_data_type, data_type_or_record_id, record_or_attachment_id, attachment_or_opts \\ [])

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

Downloads an attachment as raw bytes.

Example

{:ok, bytes} = Codat.Accounting.Attachments.download(
  client, company_id, "invoices", invoice_id, attachment_id
)
File.write!("invoice.pdf", bytes)

list(client_or_company_id, company_or_data_type, data_type_or_record_id, record_or_opts \\ [])

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

Lists all attachments for a record.

Example

{:ok, result} = Codat.Accounting.Attachments.list(
  client, company_id, "invoices", invoice_id
)

upload(client, company_id, connection_id, data_type, record_id, file_data, content_type, opts \\ [])

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

Uploads a file attachment to a record.

Parameters

  • company_id — Codat company ID
  • connection_id — data connection ID
  • data_type — e.g. "invoices", "bills", "directCosts"
  • record_id — the record to attach to
  • file_data — binary file contents
  • content_type — MIME type (e.g. "application/pdf", "image/jpeg")

Options

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