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
Deletes an attachment from a record.
Downloads an attachment as raw bytes.
Lists all attachments for a record.
upload(client, company_id, connection_id, data_type, record_id, file_data, content_type, opts \\ [])
Uploads a file attachment to a record.
Functions
@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.
@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)
@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
)
@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 IDconnection_id— data connection IDdata_type— e.g."invoices","bills","directCosts"record_id— the record to attach tofile_data— binary file contentscontent_type— MIME type (e.g."application/pdf","image/jpeg")
Options
:file_name— override the filename (default:"attachment")