Xero.Files (Xero v1.0.0)

Copy Markdown View Source

Xero Files API – Document library, folders, and accounting object associations. Base URL: https://api.xero.com/files.xro/1.0/ Scopes: files or files.read

Examples

# Upload a file to the inbox
{:ok, file} = Xero.Files.upload(token, tenant_id, "invoice.pdf", pdf_bytes, "application/pdf")

# Associate with an accounting object
:ok = Xero.Files.associate(token, tenant_id, file["FileId"], invoice_id, "Invoice")

# Download the file content
{:ok, binary} = Xero.Files.download(token, tenant_id, file["FileId"])

# Move to a folder
{:ok, _} = Xero.Files.move_to_folder(token, tenant_id, file["FileId"], folder_id)

Summary

Functions

Associates a file with a Xero accounting object.

Lists all file associations for an accounting object.

Creates a new folder.

Deletes a file from the library.

Deletes a folder (must be empty).

Removes a file association from an accounting object.

Downloads the raw binary content of a file.

Lists files in a specific folder.

Retrieves a specific folder by ID.

Lists all folders. Options: :sort

Retrieves metadata for a single file by ID.

Returns the inbox folder metadata.

Lists files in the inbox.

Lists files. Options: :page_size, :page, :sort, :sort_direction Sort values: "CreatedDateUtc" | "UpdatedDateUtc" | "Name"

Lists all associations across all files for an object group.

Moves a file to a different folder.

Uploads a file to the Xero file library (inbox by default).

Uploads a file directly into a specific folder.

Functions

associate(t, tid, file_id, object_id, object_type)

@spec associate(Xero.Auth.Token.t(), String.t(), String.t(), String.t(), String.t()) ::
  :ok | {:error, Xero.Error.t()}

Associates a file with a Xero accounting object.

Object Types

"Account" | "BankTransaction" | "Contact" | "CreditNote" | "Invoice" | "ManualJournal" | "Receipt" | "RepeatingInvoice"

associations(t, tid, object_id)

@spec associations(Xero.Auth.Token.t(), String.t(), String.t()) ::
  {:ok, term()} | {:error, Xero.Error.t()}

Lists all file associations for an accounting object.

create_folder(t, tid, name)

@spec create_folder(Xero.Auth.Token.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, Xero.Error.t()}

Creates a new folder.

delete(t, tid, id)

@spec delete(Xero.Auth.Token.t(), String.t(), String.t()) ::
  :ok | {:error, Xero.Error.t()}

Deletes a file from the library.

delete_folder(t, tid, id)

@spec delete_folder(Xero.Auth.Token.t(), String.t(), String.t()) ::
  :ok | {:error, Xero.Error.t()}

Deletes a folder (must be empty).

disassociate(t, tid, file_id, object_id)

@spec disassociate(Xero.Auth.Token.t(), String.t(), String.t(), String.t()) ::
  :ok | {:error, Xero.Error.t()}

Removes a file association from an accounting object.

download(t, tid, id)

@spec download(Xero.Auth.Token.t(), String.t(), String.t()) ::
  {:ok, binary()} | {:error, Xero.Error.t()}

Downloads the raw binary content of a file.

files_in_folder(t, tid, folder_id, opts \\ [])

@spec files_in_folder(Xero.Auth.Token.t(), String.t(), String.t(), keyword()) ::
  {:ok, term()} | {:error, Xero.Error.t()}

Lists files in a specific folder.

folder(t, tid, id)

@spec folder(Xero.Auth.Token.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, Xero.Error.t()}

Retrieves a specific folder by ID.

folders(t, tid, opts \\ [])

@spec folders(Xero.Auth.Token.t(), String.t(), keyword()) ::
  {:ok, term()} | {:error, Xero.Error.t()}

Lists all folders. Options: :sort

get(t, tid, id)

@spec get(Xero.Auth.Token.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, Xero.Error.t()}

Retrieves metadata for a single file by ID.

inbox(t, tid)

@spec inbox(Xero.Auth.Token.t(), String.t()) ::
  {:ok, map()} | {:error, Xero.Error.t()}

Returns the inbox folder metadata.

inbox_files(t, tid, opts \\ [])

@spec inbox_files(Xero.Auth.Token.t(), String.t(), keyword()) ::
  {:ok, term()} | {:error, Xero.Error.t()}

Lists files in the inbox.

list(t, tid, opts \\ [])

@spec list(Xero.Auth.Token.t(), String.t(), keyword()) ::
  {:ok, term()} | {:error, Xero.Error.t()}

Lists files. Options: :page_size, :page, :sort, :sort_direction Sort values: "CreatedDateUtc" | "UpdatedDateUtc" | "Name"

list_associations_for_object(t, tid, object_id, object_type)

@spec list_associations_for_object(
  Xero.Auth.Token.t(),
  String.t(),
  String.t(),
  String.t()
) ::
  {:ok, term()} | {:error, Xero.Error.t()}

Lists all associations across all files for an object group.

move_to_folder(t, tid, file_id, folder_id)

@spec move_to_folder(Xero.Auth.Token.t(), String.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, Xero.Error.t()}

Moves a file to a different folder.

rename(t, tid, id, new_name)

@spec rename(Xero.Auth.Token.t(), String.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, Xero.Error.t()}

Renames a file.

rename_folder(t, tid, id, new_name)

@spec rename_folder(Xero.Auth.Token.t(), String.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, Xero.Error.t()}

Renames a folder.

upload(t, tid, filename, content, content_type)

@spec upload(Xero.Auth.Token.t(), String.t(), String.t(), binary(), String.t()) ::
  {:ok, map()} | {:error, Xero.Error.t()}

Uploads a file to the Xero file library (inbox by default).

Parameters

  • filename — File name including extension (e.g. "invoice.pdf")
  • content — Binary file content
  • content_type — MIME type (e.g. "application/pdf", "image/jpeg")

upload_to_folder(t, tid, folder_id, filename, content, content_type)

@spec upload_to_folder(
  Xero.Auth.Token.t(),
  String.t(),
  String.t(),
  String.t(),
  binary(),
  String.t()
) ::
  {:ok, map()} | {:error, Xero.Error.t()}

Uploads a file directly into a specific folder.