# `Codat.Accounting.Attachments`
[🔗](https://github.com/iamkanishka/codat.git/blob/v1.0.0/lib/codat/accounting/attachments.ex#L1)

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"
    )

# `delete`

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

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

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

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

---

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